ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since a505021 was
b0c7419,
checked in by Thierry Delisle <tdelisle@…>, 5 years 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
|
Rev | Line | |
---|
[3381ed7] | 1 | #include <thread.hfa> |
---|
| 2 | #include <fstream.hfa> |
---|
| 3 | |
---|
| 4 | volatile int global = 0; |
---|
| 5 | |
---|
| 6 | thread Poller {}; |
---|
| 7 | void 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 | |
---|
| 18 | thread Waiter; |
---|
| 19 | thread Waiter {}; |
---|
| 20 | |
---|
| 21 | |
---|
[b0c7419] | 22 | volatile int count = 0; |
---|
| 23 | |
---|
| 24 | void main(Waiter & this) { |
---|
| 25 | // Get a unique id |
---|
| 26 | int id = __atomic_fetch_add(&count, 1, __ATOMIC_SEQ_CST); |
---|
[50b8885] | 27 | |
---|
[3381ed7] | 28 | for(int i = 0; i < 5; i++) { |
---|
| 29 | // Unpark this thread, don't force a yield |
---|
[b0c7419] | 30 | sout | id | "Calling unpark" | i; |
---|
| 31 | unpark(this); |
---|
[3381ed7] | 32 | |
---|
| 33 | // Force a preemption before the call to park |
---|
| 34 | int prev = global; |
---|
| 35 | while(prev == global) {} |
---|
| 36 | |
---|
| 37 | // Park this thread, |
---|
[b0c7419] | 38 | sout | id | "Parking" | i; |
---|
[3381ed7] | 39 | park(); |
---|
[b0c7419] | 40 | sout | id | "Unparked" | i; |
---|
[3381ed7] | 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | int main() { |
---|
| 45 | Poller p; |
---|
| 46 | { |
---|
| 47 | Waiter waiters[5]; |
---|
| 48 | } |
---|
| 49 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.