digitalmars.D.learn - Does anyone have an example of use of core.sync.Condition
- Matt (4/4) Mar 30 2014 I have little experience in multi-threading programming, and was
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/9) Mar 30 2014 I haven't used it either but I think this page explains the need for it:
- Jack Applegame (37/41) Mar 30 2014 Simple example of sending signal from one thread to another.
- Steven Schveighoffer (3/7) Mar 31 2014 Google thread condition variable. It's a very well-known pattern.
I have little experience in multi-threading programming, and was digging into std.concurrency, but I don't really understand the Condition class as it was used there. Could someone provide a bare-bones use of this class? I would be much obliged, thanks.
Mar 30 2014
On 03/30/2014 09:09 AM, Matt wrote:I have little experience in multi-threading programming, and was digging into std.concurrency, but I don't really understand the Condition class as it was used there. Could someone provide a bare-bones use of this class? I would be much obliged, thanks.I haven't used it either but I think this page explains the need for it: http://en.wikipedia.org/wiki/Monitor_%28synchronization%29#Condition_variables Ali
Mar 30 2014
On Sunday, 30 March 2014 at 16:09:37 UTC, Matt wrote:I have little experience in multi-threading programming, and was digging into std.concurrency, but I don't really understand the Condition class as it was used there. Could someone provide a bare-bones use of this class? I would be much obliged, thanks.Simple example of sending signal from one thread to another. import std.stdio; import core.thread; import core.sync.condition; class Foo { bool signal = false; Condition condition; this() { condition = new Condition(new Mutex); } void sendSignal() { writeln("sending signal"); synchronized(condition.mutex) { signal = true; condition.notify(); } writeln("signal sent"); } void waitForSignal() { new Thread({ writeln("waiting for signal"); synchronized(condition.mutex) { while(!signal) { condition.wait(); } } writeln("signal received"); }).start(); } } void main() { auto foo = new Foo; foo.waitForSignal(); Thread.sleep(2.seconds); foo.sendSignal(); }
Mar 30 2014
On Sun, 30 Mar 2014 12:09:35 -0400, Matt <webwraith fastmail.fm> wrote:I have little experience in multi-threading programming, and was digging into std.concurrency, but I don't really understand the Condition class as it was used there. Could someone provide a bare-bones use of this class? I would be much obliged, thanks.Google thread condition variable. It's a very well-known pattern. -Steve
Mar 31 2014