英語版
このページの英語版を見る

core.sync.event

eventモジュールは、他のスレッドへの軽量なシグナリングのためのプリミティブを提供する。 (WindowsイベントをPosix上でエミュレートする)
License:
Distributed under the Boost Software License 1.0. (See accompanying file LICENSE)
Authors:
Rainer Schuetze
struct Event;
はイベントを表す。イベントのクライアントは イベントのクライアントは、イベントが"シグナル"されるのを待つ間、一時停止される。
Posixではpthread_mutexpthread_condition を、Windowsでは CreateEvent WindowsではSetEvent
import core.sync.event, core.thread, std.file;

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

    void doProcess()
    {
        event.wait();
        // プロセスバッファ
    }

    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();
    }
}
nothrow @nogc this(bool manualReset, bool initialState);
イベントオブジェクトを作成する。
Parameters:
bool manualReset クライアントの待機を再開した後、イベントの状態は自動的にリセットされない。
bool initialState シグナルの初期状態
nothrow @nogc void initialize(bool manualReset, bool initialState);
イベント・オブジェクトを初期化する。イベントがすでに初期化されている場合は何もしない。
Parameters:
bool manualReset クライアントの待機を再開しても、イベントの状態は自動的にリセットされない。
bool initialState シグナルの初期状態
nothrow @nogc void terminate();
イベントの初期化を解除する。イベントが初期化されていない場合は何もしない。イベントが初期化されていない場合は何もしない。 スレッドが存在してはならない。
nothrow @nogc void setIfInitialized();
イベントを "signaled"に設定し、待機中のクライアントが再開されるようにする。
nothrow @nogc void reset();
イベントを手動でリセットする。
nothrow @nogc bool wait();
タイムアウトせずにイベントがシグナルされるのを待つ。
Returns:
true イベントがシグナル状態の場合、 、イベントが初期化されていないか、別のエラーが発生した場合。false
nothrow @nogc bool wait(Duration tmout);
タイムアウトでイベントがシグナルされるまで待つ。
Parameters:
Duration tmout 待ち時間の最大値
Returns:
true イベントがシグナルされた状態の場合、 、指定された時間イベントがシグナルされなかった場合、または イベントが初期化されていないか、別のエラーが発生した場合。false