Subj : Re: Win32 condition variables & MySQL To : comp.programming.threads From : Joe Seigh Date : Sat Aug 13 2005 10:08 am d|dq wrote: > Joe Seigh wrote: > >> d|dq wrote: >> >>> To my surprise, today, I realized MySQL uses the following technique: >>> >> [...] >> >> You shouldn't be suprised by now. :) >> >> > > Joe, > > In your code of Feb 14 2003: > > http://groups-beta.google.com/group/comp.programming.threads/tree/browse_frm/thread/dec4902c7f6cd24a/09cf7867c13854a7?rnum=21&hl=en&_done=%2Fgroup%2Fcomp.programming.threads%2Fbrowse_frm%2Fthread%2Fdec4902c7f6cd24a%3F#doc_1546cac7cd68c5fc > > > I don't know what algorithm you are actually using. Is it documented > somewhere or did you make it up? > > I need to educate myself because I don't fully understand the roles of > the following items: > > typedef struct waitset_tt { > struct waitset_tt *next; > LONG refCount; > ^^^^^^^^^^^^^^ > > LONG waitCount; > > LONG deferCount; > ^^^^^^^^^^^^^^^^ > > HANDLE sem; > > } waitset_t; > > typedef struct { > qfree_t *fq; > > waitset_t *waitset1; > ^^^^^^^^^^^^^^^^^^^^ > > waitset_t *waitset2; > ^^^^^^^^^^^^^^^^^^^^ > > CRITICAL_SECTION cs; > > condattr_t attr; > } cond_t; Two waitsets are used so that when signal is used, threads that wait *after* the signal won't be woken up. Refcounting is used since waiting threads can take an arbitrary amount of time and you don't want to delete or reuse a waitset until prior waiters have finished with it. Some implementations just block everybody, including signalers, until the slow threads finish, no matter how long that takes. deferCount is just a shadow copy of the semaphore value so you can make inferences about cancelation of waits. This version doesn't do timeouts according to Posix semantics I think. You probably don't want to do Posix semantics if you don't have to as Posix forces a suboptimal implementation. > > Could you point me to some reading materials or put me in the right > direction in any way? Just http://www.cs.wustl.edu/~schmidt/win32-cv-1.html which should let you know what the issues are. The problems just boil down do events vs. eventcounts or semaphores vs. eventcounts. And maybe signal vs. broadcast as far as what it means for implementing waitsets. For extra credit you can figure out what exactly is braindamaged about Posix timeouts. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .