source:
src/tests/thread.c
@
026a0f5
Last change on this file since 026a0f5 was bd4d011, checked in by , 8 years ago | |
---|---|
|
|
File size: 862 bytes |
Rev | Line | |
---|---|---|
[0c92c9f] | 1 | #include <fstream> |
2 | #include <kernel> | |
3 | #include <stdlib> | |
[4a3334cf] | 4 | #include <thread> |
[0c92c9f] | 5 | |
[bd4d011] | 6 | // thread First; |
7 | // void main(First* this); | |
[0c92c9f] | 8 | |
[bd4d011] | 9 | // thread Second; |
10 | // void main(Second* this); | |
11 | ||
12 | thread First { signal_once* lock; }; | |
13 | thread Second { signal_once* lock; }; | |
[0c92c9f] | 14 | |
[ee897e4b] | 15 | void ?{}( First * this, signal_once* lock ) { this->lock = lock; } |
16 | void ?{}( Second * this, signal_once* lock ) { this->lock = lock; } | |
[0c92c9f] | 17 | |
18 | void main(First* this) { | |
19 | for(int i = 0; i < 10; i++) { | |
20 | sout | "First : Suspend No." | i + 1 | endl; | |
21 | yield(); | |
22 | } | |
[ee897e4b] | 23 | signal(this->lock); |
[0c92c9f] | 24 | } |
25 | ||
26 | void main(Second* this) { | |
[ee897e4b] | 27 | wait(this->lock); |
[0c92c9f] | 28 | for(int i = 0; i < 10; i++) { |
29 | sout | "Second : Suspend No." | i + 1 | endl; | |
30 | yield(); | |
31 | } | |
32 | } | |
33 | ||
34 | ||
35 | int main(int argc, char* argv[]) { | |
[ee897e4b] | 36 | signal_once lock; |
[0c92c9f] | 37 | sout | "User main begin" | endl; |
38 | { | |
[ee897e4b] | 39 | processor p; |
[0c92c9f] | 40 | { |
[bd4d011] | 41 | First f = { &lock }; |
42 | Second s = { &lock }; | |
[0c92c9f] | 43 | } |
44 | } | |
45 | sout | "User main end" | endl; | |
46 | } |
Note: See TracBrowser
for help on using the repository browser.