source:
src/tests/concurrent/coroutineYield.c
@
863c413
Last change on this file since 863c413 was b9da9585, checked in by , 6 years ago | |
---|---|
|
|
File size: 651 bytes |
Rev | Line | |
---|---|---|
[82c948c] | 1 | #include <fstream> |
2 | #include <kernel> | |
3 | #include <stdlib> | |
4 | #include <thread> | |
[b9da9585] | 5 | #include <time> |
6 | ||
7 | #ifndef PREEMPTION_RATE | |
8 | #define PREEMPTION_RATE 10`ms | |
9 | #endif | |
10 | ||
11 | Duration default_preemption() { | |
12 | return PREEMPTION_RATE; | |
13 | } | |
[82c948c] | 14 | |
[70969f8] | 15 | #ifdef LONG_TEST |
16 | static const unsigned long N = 600_000ul; | |
17 | #else | |
18 | static const unsigned long N = 1_000ul; | |
19 | #endif | |
20 | ||
[82c948c] | 21 | coroutine Coroutine {}; |
22 | ||
23 | void main(Coroutine& this) { | |
[7323573] | 24 | while(true) { |
25 | sout | "Coroutine 1" | endl; | |
26 | yield(); | |
27 | sout | "Coroutine 2" | endl; | |
28 | suspend(); | |
29 | } | |
[82c948c] | 30 | } |
31 | ||
32 | ||
33 | int main(int argc, char* argv[]) { | |
34 | Coroutine c; | |
[70969f8] | 35 | for(int i = 0; i < N; i++) { |
[7323573] | 36 | sout | "Thread 1" | endl; |
37 | resume(c); | |
38 | sout | "Thread 2" | endl; | |
39 | yield(); | |
40 | } | |
[82c948c] | 41 | } |
Note: See TracBrowser
for help on using the repository browser.