source: tests/concurrent/preempt2.cfa @ 153d3440

ADTast-experimental
Last change on this file since 153d3440 was fc72696c, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Added second preempt test that checks the same thing but using a different technique

  • Property mode set to 100644
File size: 743 bytes
Line 
1#include <fstream.hfa>
2#include <thread.hfa>
3#include <time.hfa>
4
5#include "long_tests.hfa"
6
7#ifndef PREEMPTION_RATE
8#define PREEMPTION_RATE 10`ms
9#endif
10
11Duration default_preemption() {
12        return PREEMPTION_RATE;
13}
14
15#ifdef TEST_LONG
16static const unsigned long N = 30_000ul;
17#else
18static const unsigned long N = 500ul;
19#endif
20
21extern void __cfaabi_check_preemption();
22
23static struct {
24        volatile int x;
25        volatile int y;
26} globals;
27
28thread T1 {};
29void main(T1 &) {
30        for() {
31                if ( globals.x == N ) break;
32                if ( globals.x < globals.y ) globals.x += 1;
33        }
34}
35
36thread T2 {};
37void main(T2 &) {
38        for() {
39                if ( globals.y == N ) break;
40                if ( globals.y == globals.x ) globals.y += 1;
41        }
42}
43
44int main() {
45        {
46                T1 t1;
47                T2 t2;
48        }
49        sout | "Done";
50} // main
Note: See TracBrowser for help on using the repository browser.