source: src/tests/concurrent/preempt.c@ f74eb47

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 with_gc
Last change on this file since f74eb47 was 0f56058, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

divide "time" into type and functions

  • Property mode set to 100644
File size: 721 bytes
RevLine 
[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]9Duration default_preemption() {
[11dbfe1]10 return PREEMPTION_RATE;
11}
12
13static volatile int counter = 0;
14
[0322865c]15thread worker_t {
[11dbfe1]16 int value;
17};
18
[2afec66]19void ?{}( worker_t & this, int value ) {
20 this.value = value;
[11dbfe1]21}
22
[83a071f9]23void 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
32int 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.