source: tests/concurrency/sleep.cfa @ ad47ec4

Last change on this file since ad47ec4 was c26bea2a, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

first attempt at renaming directory tests/concurrent to tests/concurrency to harmonize with other concurrency directory names

  • Property mode set to 100644
File size: 717 bytes
Line 
1#include <fstream.hfa>
2#include <thread.hfa>
3#include <mutex_stmt.hfa>
4#include <time.hfa>
5
6Duration default_preemption() {
7        return 0;
8}
9
10volatile int counter = 0;
11
12thread fast_sleeper {};
13void main(fast_sleeper &) {
14        Duration wait = 47`ms;
15        for(i; 20) {
16                sleep(wait);
17                __atomic_fetch_add( &counter, 1, __ATOMIC_RELAXED );
18        }
19}
20
21thread slow_sleeper {};
22void main(slow_sleeper &) {
23        Duration wait = 277`ms;
24        for(i; 4) {
25                sleep(wait);
26                int val = __atomic_add_fetch( &counter, -5, __ATOMIC_RELAXED );
27                if(val < -9) abort | "Value reached negative value:" | val;
28        }
29}
30
31int main() {
32        mutex( sout ) sout | "start";
33        {
34                slow_sleeper slow;
35                yield();
36                fast_sleeper fast;
37                yield();
38        }
39        mutex( sout ) sout | "done";
40}
41
Note: See TracBrowser for help on using the repository browser.