Waits on c until another thread calls wake or wake_all. It can return without either, so check the condition again afterwards.
- m: the mutex the caller holds. It is released while waiting and held again when
waitreturns.
wait :: (c: *Condition_Variable, m: *Mutex)
Waits on c until another thread calls wake or wake_all. It can return without either, so check the condition again afterwards.
Parameters
- m: *Mutex
- the mutex the caller holds. It is released while waiting and held again when
waitreturns.
wait :: (c: *Condition_Variable, m: *Mutex)
Waits on c until another thread calls wake or wake_all. It can return without either, so check the condition again afterwards.
Parameters
- m: *Mutex
- the mutex the caller holds. It is released while waiting and held again when
waitreturns.
Box :: struct { mutex: Mutex; changed: Condition_Variable; done: bool; }
finish :: (thread: *Thread) -> s64 {
box := cast(*Box) thread.data;
lock(*box.mutex);
box.done = true;
unlock(*box.mutex);
wake(*box.changed);
return 0;
}
box: Box;
init(*box.mutex);
init(*box.changed);
thread: Thread;
assert(thread_init(*thread, finish));
thread.data = *box;
thread_start(*thread);
lock(*box.mutex);
while !box.done wait(*box.changed, *box.mutex);
unlock(*box.mutex);
assert(thread_is_done(*thread, -1));
thread_deinit(*thread);