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