source: tests/concurrent/preempt.cfa @ 01f78e0

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since 01f78e0 was c701332a, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Cleanup of builtin atomics to remove _1,2,4 suffix versions and support all basic ints

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include <kernel.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 volatile int counter = 0;
24
25thread worker_t {
26        int value;
27};
28
29void ?{}( worker_t & this, int value ) {
30        this.value = value;
31}
32
33void main(worker_t & this) {
34        while(TEST(counter < N)) {
35                __cfaabi_check_preemption();
36                if( (counter % 7) == this.value ) {
37                        __cfaabi_check_preemption();
38                        int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
39                        __cfaabi_check_preemption();
40                        if( (next % 100) == 0 ) printf("%d\n", (int)next);
41                        __cfaabi_check_preemption();
42                }
43                __cfaabi_check_preemption();
44                KICK_WATCHDOG;
45        }
46}
47
48int main(int argc, char* argv[]) {
49        processor p;
50        {
51                worker_t w0 = 0;
52                worker_t w1 = 1;
53                worker_t w2 = 2;
54                worker_t w3 = 3;
55                worker_t w4 = 4;
56                worker_t w5 = 5;
57                worker_t w6 = 6;
58        }
59}
Note: See TracBrowser for help on using the repository browser.