Condition variables?

David Brown dlang at davidb.org
Sat Sep 29 21:58:06 PDT 2007


Hopefully I'm missing something obvious here, but D and phobos seem to
be missing any kind of condition variables.  It's really hard to do
non-trivial thread programming without this kind of synchronization.

In fact, I'm not sure how I could even go about implementing
something, since there doesn't seem to be any way of easily accessing
the object's monitor, which would be needed to do condition variables
that work with 'synchronized'.

I can think of other ways of doing synchronization, but not in a
terribly efficient way:

  - Use Thread's pause() and resume().  I would have to implement wait
    queues and getting synchronization right on this would be
    challenging.

  - Use another OS mechanism such as pipes to sleep and wakeup.  This
    is also not very efficient.

I'm just kind of wondering why std.thread even exists without
condition variables, since it really isn't useful for all that much,
by itself, and doesn't seem to even have the needed hooks to implement
any other mechanism.

David Brown



More information about the Digitalmars-d mailing list