source: tests/concurrent/preempt.cfa@ 97fed44

ADT ast-experimental enum forall-pointer-decay pthread-emulation qualifiedEnum
Last change on this file since 97fed44 was b200492, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Fixed last push which wasn't checked properly.

  • Property mode set to 100644
File size: 1.3 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 unsigned spin;
29};
30
31void ?{}( worker_t & this, int value ) {
32 this.value = value;
33 this.spin = 0;
34}
35
36void main(worker_t & this) {
37 while(TEST(counter < N)) {
38 if(this.spin > 100_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")";
39 __cfaabi_check_preemption();
40 if( (counter % 7) == this.value ) {
41 __cfaabi_check_preemption();
42 int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
43 __cfaabi_check_preemption();
44 if( (next % 100) == 0 ) printf("%d\n", (int)next);
45 __cfaabi_check_preemption();
46 this.spin = 0;
47 }
48 __cfaabi_check_preemption();
49 KICK_WATCHDOG;
50 this.spin++;
51 }
52}
53
54int main(int argc, char* argv[]) {
55 processor p;
56 {
57 worker_t w0 = 0;
58 worker_t w1 = 1;
59 worker_t w2 = 2;
60 worker_t w3 = 3;
61 worker_t w4 = 4;
62 worker_t w5 = 5;
63 worker_t w6 = 6;
64 }
65}
Note: See TracBrowser for help on using the repository browser.