source: tests/concurrent/sleep.cfa@ 180f249

ADT ast-experimental enum forall-pointer-decay pthread-emulation qualifiedEnum
Last change on this file since 180f249 was 7bd23ce, checked in by Thierry Delisle <tdelisle@…>, 4 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
5Duration default_preemption() {
6 return 0;
7}
8
9volatile int counter = 0;
10
11thread fast_sleeper {};
12void 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
20thread slow_sleeper {};
21void 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
30int 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.