Possible deadlock and solution

Matthias Andree matthias.andree at gmx.de
Fri Sep 27 19:57:04 CEST 2002


On Fri, 27 Sep 2002, Gyepi SAM wrote:

> The solution:
> 
> Ensure that register_words always locks the databases in the same order by
> 1. Changing the declaration of register_words from
> 
>   void register_words(int fd, wordlist_t *list, wordlist_t *other);
> 
> to
> 
>   void register_words(int fd, wordlist_t *good, wordlist_t *bad, int transfer_order);

The real solution when you're about to lock two items that may be
interdependent is to do this (pseudo code):

for(;;) {
  obtain_blocking(a);
  if (!obtain_nonblocking(b)) {
    /* release all that we acquired so far, sleep and retry */
    release(a); sleep(1); continue;
  }

  /* work with a, b */

  release(b);
  release(a);
  break;
}



More information about the bogofilter-dev mailing list