Event

represents an event. Clients of an event are suspended while waiting for the event to be "signaled".

Implemented using pthread_mutex and pthread_condition on Posix and CreateEvent and SetEvent on Windows.

import core.sync.event, core.thread, std.file;

struct ProcessFile
{
    ThreadGroup group;
    Event event;
    void[] buffer;

    void doProcess()
    {
        event.wait();
        // process buffer
    }

    void process(string filename)
    {
        event.initialize(true, false);
        group = new ThreadGroup;
        for (int i = 0; i < 10; ++i)
            group.create(&doProcess);

        buffer = std.file.read(filename);
        event.set();
        group.joinAll();
        event.terminate();
    }
}

Constructors

this
this(bool manualReset, bool initialState)

Creates an event object.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Postblit

A postblit is present on this object, but not explicitly documented in the source.

Members

Functions

initialize
void initialize(bool manualReset, bool initialState)

Initializes an event object. Does nothing if the event is already initialized.

reset
void reset()

Reset the event manually

set
void set()

Set the event to "signaled", so that waiting clients are resumed

terminate
void terminate()

* deinitialize event. Does nothing if the event is not initialized. There must not be * threads currently waiting for the event to be signaled.

wait
bool wait()

Wait for the event to be signaled without timeout.

wait
bool wait(Duration tmout)

Wait for the event to be signaled with timeout.

Meta