ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 2e19e91 was
7bd23ce,
checked in by Thierry Delisle <tdelisle@…>, 3 years ago
|
Tentative fix to sleep.cfa make it more robust
|
-
Property mode set to
100644
|
File size:
683 bytes
|
Line | |
---|
1 | #include <fstream.hfa> |
---|
2 | #include <thread.hfa> |
---|
3 | #include <time.hfa> |
---|
4 | |
---|
5 | Duration default_preemption() { |
---|
6 | return 0; |
---|
7 | } |
---|
8 | |
---|
9 | volatile int counter = 0; |
---|
10 | |
---|
11 | thread fast_sleeper {}; |
---|
12 | void main(fast_sleeper &) { |
---|
13 | Duration wait = 47`ms; |
---|
14 | for(i; 20) { |
---|
15 | sleep(wait); |
---|
16 | __atomic_fetch_add( &counter, 1, __ATOMIC_RELAXED ); |
---|
17 | } |
---|
18 | } |
---|
19 | |
---|
20 | thread slow_sleeper {}; |
---|
21 | void main(slow_sleeper &) { |
---|
22 | Duration wait = 277`ms; |
---|
23 | for(i; 4) { |
---|
24 | sleep(wait); |
---|
25 | int val = __atomic_add_fetch( &counter, -5, __ATOMIC_RELAXED ); |
---|
26 | if(val < -9) abort | "Value reached negative value:" | val; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | int main() { |
---|
31 | sout | acquire | "start"; |
---|
32 | { |
---|
33 | slow_sleeper slow; |
---|
34 | yield(); |
---|
35 | fast_sleeper fast; |
---|
36 | yield(); |
---|
37 | } |
---|
38 | sout | acquire | "done"; |
---|
39 | } |
---|
40 | |
---|
Note: See
TracBrowser
for help on using the repository browser.