Go to file
Tristan B. Velloza Kildaire eeab29d54e - Added license 2023-02-23 15:47:46 +02:00
branding - Added logo 2023-02-23 15:27:49 +02:00
source/libsnooze - Refactored into a package 2023-02-23 15:21:54 +02:00
.gitignore Initial implementation 2023-02-23 15:16:24 +02:00
LICENSE - Added license 2023-02-23 15:47:46 +02:00
README.md - Fixed formatting 2023-02-23 15:41:51 +02:00
dub.json Initial implementation 2023-02-23 15:16:24 +02:00

README.md


libsnooze

A wait/notify mechanism for D




Usage

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.notify();