source: src/tests/preempt.c@ bdeba0b

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since bdeba0b was 11dbfe1, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Added test to validate preemption is still active

  • Property mode set to 100644
File size: 688 bytes
Line 
1#include <kernel>
2#include <thread>
3
4#ifndef PREEMPTION_RATE
5#define PREEMPTION_RATE 10_000ul
6#endif
7
8unsigned int default_preemption() {
9 return PREEMPTION_RATE;
10}
11
12static volatile int counter = 0;
13
14thread Worker {
15 int value;
16};
17
18void ?{}( Worker * this, int value ) {
19 this->value = value;
20}
21
22void main(Worker * this) {
23 while(counter < 1000) {
24 if( (counter % 7) == this->value ) {
25 int next = __atomic_add_fetch_4(&counter, 1, __ATOMIC_SEQ_CST);
26 if( (next % 100) == 0 ) printf("%d\n", next);
27 }
28 }
29}
30
31int main(int argc, char* argv[]) {
32 processor p;
33 {
34 Worker w0 = 0;
35 Worker w1 = 1;
36 Worker w2 = 2;
37 Worker w3 = 3;
38 Worker w4 = 4;
39 Worker w5 = 5;
40 Worker w6 = 6;
41 }
42}
Note: See TracBrowser for help on using the repository browser.