source: tests/concurrent/sleep.cfa @ c8238c0

ADTast-experimental
Last change on this file since c8238c0 was 237df76, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

convert from test programs I/O acquire to mutex statement

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