class sys.Event

Overview

This class provides standard means of synchronization between threads. More…

import "sys_Event.jnc"

class Event {
    // construction

    construct();
    destruct();

    // methods

    void signal();
    void reset();
    bool wait(uint_t timeout = -1);
};

Detailed Documentation

This class provides standard means of synchronization between threads.

sys.Event can be in one of the following two states: idle or signalled. One or more threads can wait until the event becomes signalled by invoking wait method. When some other thread signals the event by invoking signal method, the first thread in the queue of waiting threads wakes up, wait call finishes, and the event goes back to idle state.

Code sample:

import "sys_Event.jnc"

sys.Event g_event;

thread1() {
    // ...

    g_event.wait(); // thread sleeps here until event is signalled

    // continue...
}

thread2() {
    // ...

    g_event.signal(); // thread1 wakes up and continues;
                       // g_event goes back to non-signalled state
}

See also:

sys.NotificationEvent, sys.Lock, sys.Thread

Methods

void signal()

Sets event to signalled state. When the first waiting thread in the queue wakes up, the event goes back to idle state.

void reset()

Forcefully returns event to idle state.

bool wait(uint_t timeout = -1)

Waits until event goes to signalled state. When it happens, wait returns true and the event goes back to idle state.

If timeout parameter is not -1 then it’s a wait with a time limit. If the event does not get signalled until timeout expires, wait return false. Timeout is expressed in milliseconds.