Condition variables?
Sean Kelly
sean at f4.ca
Sun Sep 30 08:58:52 PDT 2007
David Brown wrote:
> 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'.
Tango has them in tango.core.sync.Condition. They need to work with
Tango's mutexes (tango.core.sync.Mutex), and those mutexes work with
'synchronized':
auto m = new Mutex;
auto c = new Condition;
data[] d;
// thread A
synchronized( m )
{
while( d.length == 0 )
c.wait();
// use data
}
// thread B
synchronized( m )
{
d ~= something;
c.notify();
}
Sean
More information about the Digitalmars-d
mailing list