source: tests/concurrent/sleep.cfa @ 247d4ac

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since 247d4ac 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
RevLine 
[c457dc41]1#include <fstream.hfa>
2#include <thread.hfa>
3#include <time.hfa>
4
5Duration default_preemption() {
6        return 0;
7}
8
[7bd23ce]9volatile int counter = 0;
10
[c457dc41]11thread fast_sleeper {};
12void main(fast_sleeper &) {
13        Duration wait = 47`ms;
14        for(i; 20) {
15                sleep(wait);
[7bd23ce]16                __atomic_fetch_add( &counter, 1, __ATOMIC_RELAXED );
[c457dc41]17        }
18}
19
20thread slow_sleeper {};
21void main(slow_sleeper &) {
22        Duration wait = 277`ms;
23        for(i; 4) {
24                sleep(wait);
[7bd23ce]25                int val = __atomic_add_fetch( &counter, -5, __ATOMIC_RELAXED );
26                if(val < -9) abort | "Value reached negative value:" | val;
[c457dc41]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.