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