source: src/tests/concurrent/coroutineYield.c@ 4d7fb9e

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 4d7fb9e was b9da9585, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Fixed long run tests

  • Property mode set to 100644
File size: 651 bytes
Line 
1#include <fstream>
2#include <kernel>
3#include <stdlib>
4#include <thread>
5#include <time>
6
7#ifndef PREEMPTION_RATE
8#define PREEMPTION_RATE 10`ms
9#endif
10
11Duration default_preemption() {
12 return PREEMPTION_RATE;
13}
14
15#ifdef LONG_TEST
16static const unsigned long N = 600_000ul;
17#else
18static const unsigned long N = 1_000ul;
19#endif
20
21coroutine Coroutine {};
22
23void main(Coroutine& this) {
24 while(true) {
25 sout | "Coroutine 1" | endl;
26 yield();
27 sout | "Coroutine 2" | endl;
28 suspend();
29 }
30}
31
32
33int main(int argc, char* argv[]) {
34 Coroutine c;
35 for(int i = 0; i < N; i++) {
36 sout | "Thread 1" | endl;
37 resume(c);
38 sout | "Thread 2" | endl;
39 yield();
40 }
41}
Note: See TracBrowser for help on using the repository browser.