source: tests/concurrent/preempt.cfa @ c0f881b

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since c0f881b was c0f881b, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Added spin count to the debug test to help identify why it's timing out.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <fstream.hfa>
2#include <kernel.hfa>
3#include <thread.hfa>
4#include <time.hfa>
5
6#include "long_tests.hfa"
7
8#ifndef PREEMPTION_RATE
9#define PREEMPTION_RATE 10`ms
10#endif
11
12Duration default_preemption() {
13        return PREEMPTION_RATE;
14}
15
16#ifdef TEST_LONG
17static const unsigned long N = 30_000ul;
18#else
19static const unsigned long N = 500ul;
20#endif
21
22extern void __cfaabi_check_preemption();
23
24static volatile int counter = 0;
25
26thread worker_t {
27        int value;
28};
29
30void ?{}( worker_t & this, int value ) {
31        this.value = value;
32}
33
34void main(worker_t & this) {
35        unsigned spin = 0;
36        while(TEST(counter < N)) {
37                if(spin > 100_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | spin | ")";
38                __cfaabi_check_preemption();
39                if( (counter % 7) == this.value ) {
40                        __cfaabi_check_preemption();
41                        int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
42                        __cfaabi_check_preemption();
43                        if( (next % 100) == 0 ) printf("%d\n", (int)next);
44                        __cfaabi_check_preemption();
45                        spin = 0;
46                }
47                __cfaabi_check_preemption();
48                KICK_WATCHDOG;
49                spin++;
50        }
51}
52
53int main(int argc, char* argv[]) {
54        processor p;
55        {
56                worker_t w0 = 0;
57                worker_t w1 = 1;
58                worker_t w2 = 2;
59                worker_t w3 = 3;
60                worker_t w4 = 4;
61                worker_t w5 = 5;
62                worker_t w6 = 6;
63        }
64}
Note: See TracBrowser for help on using the repository browser.