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