core.sync.event

The event module provides a primitive for lightweight signaling of other threads (emulating Windows events on Posix)

struct Event

Types 1

structEvent
  • 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.setIfInitialized();
            group.joinAll();
            event.terminate();
        }
    }
Methods
void initialize(bool manualReset, bool initialState) nothrow @nogcInitializes an event object. Does nothing if the event is already initialized.
void opAssign(Event) @disable nothrow @nogc
void terminate() nothrow @nogcdeinitialize event. Does nothing if the event is not initialized. There must not be threads currently waiting for the event to be signaled.
void set() nothrow @nogc
void setIfInitialized() nothrow @nogcSet the event to "signaled", so that waiting clients are resumed
void reset() nothrow @nogcReset the event manually
bool wait() nothrow @nogcWait for the event to be signaled without timeout.
bool wait(Duration tmout) nothrow @nogcWait for the event to be signaled with timeout.
Constructors
this(bool manualReset, bool initialState)Creates an event object.
Destructors