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