source:
src/tests/concurrent/preempt.c
@
9ca94af
Last change on this file since 9ca94af was 0f56058, checked in by , 6 years ago | |
---|---|
|
|
File size: 721 bytes |
Rev | Line | |
---|---|---|
[11dbfe1] | 1 | #include <kernel> |
2 | #include <thread> | |
[0f56058] | 3 | #include <time> |
[11dbfe1] | 4 | |
5 | #ifndef PREEMPTION_RATE | |
[8ad6533] | 6 | #define PREEMPTION_RATE 10`ms |
[11dbfe1] | 7 | #endif |
8 | ||
[8ad6533] | 9 | Duration default_preemption() { |
[11dbfe1] | 10 | return PREEMPTION_RATE; |
11 | } | |
12 | ||
13 | static volatile int counter = 0; | |
14 | ||
[0322865c] | 15 | thread worker_t { |
[11dbfe1] | 16 | int value; |
17 | }; | |
18 | ||
[2afec66] | 19 | void ?{}( worker_t & this, int value ) { |
20 | this.value = value; | |
[11dbfe1] | 21 | } |
22 | ||
[83a071f9] | 23 | void main(worker_t & this) { |
[11dbfe1] | 24 | while(counter < 1000) { |
[83a071f9] | 25 | if( (counter % 7) == this.value ) { |
[11dbfe1] | 26 | int next = __atomic_add_fetch_4(&counter, 1, __ATOMIC_SEQ_CST); |
[12d2dc8] | 27 | if( (next % 100) == 0 ) printf("%d\n", (int)next); |
[11dbfe1] | 28 | } |
29 | } | |
30 | } | |
31 | ||
32 | int main(int argc, char* argv[]) { | |
33 | processor p; | |
34 | { | |
[0322865c] | 35 | worker_t w0 = 0; |
36 | worker_t w1 = 1; | |
37 | worker_t w2 = 2; | |
38 | worker_t w3 = 3; | |
39 | worker_t w4 = 4; | |
40 | worker_t w5 = 5; | |
41 | worker_t w6 = 6; | |
[11dbfe1] | 42 | } |
[2afec66] | 43 | } |
Note: See TracBrowser
for help on using the repository browser.