Subj : Re: win32 threads broken (was Win32 condition variables redux) To : comp.programming.threads From : Joe Seigh Date : Wed Aug 03 2005 01:12 pm d|dq wrote: > Joe, > > Thanks for jumping in. I appreciate your insight. > > You seem to say (even) "CV redux" can't be programmed easily using > Win32 primitives. > > Implementations I have seen rely on: > - one or more critical sections > - one or more semaphores > - up to half a dozen counters > - a data structure such as a queue or a doubly-linked linked list > - a few Interlocked* this or Interlocked* that > - up to a 1,000 lines of C code Well, it can be complicated but some people may make it more complicated than it has to be. > > That's a lot of code to digest. In the end, it's very difficult to > determine if problems are hidden in such complex implementations. (And > I can't believe so much code and "logic" improves performance.) That's why low level synchronization primatives are important. If the platform provider makes bad choices, this is what you get. > > Example: The Apache Portable Runtime (APR) > A Win32 implementation of condition variables has been part of APR for > several years. People thought it worked. a few days ago, 2 patches had > to be applied because it didn't work at all, even with 2 threads. We spotted it right away since we already knew win32 condition variables were problematic. > > That's just one example. There are many others. None of them give our > industry a good name. > > But, going back to "CV redux"... > > Could it be done with: > - 1 auto-reset event object > (using WaitForSingleObject to wait and SetEvent to communicate a > broadcast to all waiting threads by repeatedly marking the event > signaled) > - 1 "broadcast" flag > - 1 "waiting" counter > > ? No. If there was a simple way, we'd all use that instead of coming up with complicated solutions. > > PS: According to several Microsoft employees, PulseEvent should be > avoided like the plague. I even read that it remains in the Win32 API > for backward compatibility reasons only. > The documentation mentions that also. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .