mirror of https://github.com/deavmi/libsnooze
A wait/notify mechanism for D
https://deavmi.assigned.network/projects/libsnooze
Tristan B. Velloza Kildaire
06be5ee5c9
- Documented module |
||
---|---|---|
.github/workflows | ||
branding | ||
source/libsnooze | ||
.gitignore | ||
LICENSE | ||
README.md | ||
dub.json |
README.md
libsnooze
A wait/notify mechanism for D
API
To see the full documentation (which is always up-to-date) check it out on DUB.
Usage
Importing issues
Currently importing just with import libsnooze
is broken, we recommend you import as follows:
import libsnooze.clib;
import libsnooze;
Which should build!
Example
Firstly we create an Event
which is something that can be notified or awaited on. This is simply accomplished as follows:
Event myEvent = new Event();
Now let's create a thread which consumes myEvent
and waits on it:
class TestThread : Thread
{
private Event event;
this(Event event)
{
super(&worker);
this.event = event;
}
public void worker()
{
writeln("("~to!(string)(Thread.getThis().id())~") Thread is waiting...");
event.wait();
writeln("("~to!(string)(Thread.getThis().id())~") Thread is waiting... [done]");
}
}
TestThread thread1 = new TestThread(event);
thread1.start();
Now on the main thread we can do the following to wakeup waiting threads:
/* Wake up all sleeping on this event */
event.notifyAll();