source: tests/concurrent/park/force_preempt.cfa @ b0c7419

arm-ehjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since b0c7419 was b0c7419, checked in by Thierry Delisle <tdelisle@…>, 22 months ago

Yield now uses force_yield instead of park/unpark.
Final ctxswitch of a thread now uses ad-hoc mechanism instead of park/unpark.

  • Property mode set to 100644
File size: 778 bytes
Line 
1#include <thread.hfa>
2#include <fstream.hfa>
3
4volatile int global = 0;
5
6thread Poller {};
7void main(Poller & this) {
8        while(true) {
9                waitfor( ^?{} : this ) {
10                        break;
11                } or else {
12                        global = (global + 1) % 10;
13                        yield();
14                }
15        }
16}
17
18thread Waiter;
19thread Waiter {};
20
21
22volatile int count = 0;
23
24void main(Waiter & this) {
25        // Get a unique id
26        int id = __atomic_fetch_add(&count, 1, __ATOMIC_SEQ_CST);
27
28        for(int i = 0; i < 5; i++) {
29                // Unpark this thread, don't force a yield
30                sout | id | "Calling unpark" | i;
31                unpark(this);
32
33                // Force a preemption before the call to park
34                int prev = global;
35                while(prev == global) {}
36
37                // Park this thread,
38                sout | id | "Parking" | i;
39                park();
40                sout | id | "Unparked" | i;
41        }
42}
43
44int main() {
45        Poller p;
46        {
47                Waiter waiters[5];
48        }
49}
Note: See TracBrowser for help on using the repository browser.