Class TaskCondition
Event loop based condition variable or "event" implementation.
This class can be used in exchange for a core.sync.condition.Condition to avoid blocking the event loop when waiting.
Inherits from
-
core
(base class).sync .condition .Condition
Constructors
Name | Description |
---|---|
this
|
Properties
Name | Type | Description |
---|---|---|
mutex
[get]
|
core |
Methods
Name | Description |
---|---|
notify
|
|
notifyAll
|
|
wait
|
|
wait
|
Notice
Because this class is annotated nothrow, it cannot be interrupted
using vibe
(). The corresponding
InterruptException will be deferred until the next blocking
operation yields to the event loop.
Use InterruptibleTaskCondition
as an alternative that can be
interrupted.
Note that it is generally not safe to use a TaskCondition
together with an
interruptible mutex
type.
See Also
Example
This example shows the typical usage pattern using a while
loop to make
sure that the final condition is reached.
import vibe .core .core;
__gshared Mutex mutex;
__gshared TaskCondition condition;
__gshared int workers_still_running = 0;
// setup the task condition
mutex = new Mutex;
condition = new TaskCondition(mutex);
// start up the workers and count how many are running
foreach (i; 0 .. 4) {
workers_still_running++;
runWorkerTask({
// simulate some work
sleep(100 .msecs);
// notify the waiter that we're finished
synchronized (mutex)
workers_still_running--;
condition .notify();
});
}
// wait until all tasks have decremented the counter back to zero
synchronized (mutex) {
while (workers_still_running > 0)
condition .wait();
}
Authors
Leonid Kramer, Sönke Ludwig, Manuel Frischknecht
Copyright
© 2012-2015 RejectedSoftware e.K.
License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.