#include #include volatile int global = 0; thread Poller {}; void main(Poller & this) { while(true) { waitfor( ^?{} : this ) { break; } or else { global = (global + 1) % 10; yield(); } } } thread Waiter; thread Waiter {}; volatile int count = 0; void main(Waiter & this) { // Get a unique id int id = __atomic_fetch_add(&count, 1, __ATOMIC_SEQ_CST); for(int i = 0; i < 5; i++) { // Unpark this thread, don't force a yield sout | id | "Calling unpark" | i; unpark(this); // Force a preemption before the call to park int prev = global; while(prev == global) {} // Park this thread, sout | id | "Parking" | i; park(); sout | id | "Unparked" | i; } } int main() { Poller p; { Waiter waiters[5]; } }