Condition variables?
Sean Kelly
sean at f4.ca
Tue Oct 2 09:43:17 PDT 2007
Steven Schveighoffer wrote:
> "Sean Kelly" <sean at f4.ca> wrote in message
> news:fdtqpn$259o$1 at digitalmars.com...
>> Steven Schveighoffer wrote:
>>> So the code above has to do something special by unlocking the object
>>> before waiting using an atomic operation. I think this requires some
>>> language support.
>> Doing this efficiently typically requires OS support. The library must
>> indicate to the OS that a context switch may not occur while certain
>> portions of the code are executing. It is possible to implement condvars
>> without OS support as well, but the implementation tends to be fairly
>> complicated. Look for version(Win32) blocks in the Tango implementation
>> for one such example.
>
> Why can't you use SignalObjectAndWait? Are you not using Win32 Mutexes in
> Win32?
Nope. Critical sections. For what it's worth, the Tango condvar
implementation is pretty similar to the one in Boost.
> I implemented a C++ OS abstraction library, and I had no problems
> implementing conditions on Win32 using OS support...
Frankly, I've never used SignalObjectAndWait. I think the only place
things may get a bit weird is in a notifyAll routine. I guess you'd
have to use a semaphore for the wait object and perhaps a separate
counter to track the number of threads waiting on it?
Sean
More information about the Digitalmars-d
mailing list