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