source:
tests/concurrent/thread.cfa
@
87e0b015
Last change on this file since 87e0b015 was 924c5ce, checked in by , 5 years ago | |
---|---|
|
|
File size: 812 bytes |
Rev | Line | |
---|---|---|
[73abe95] | 1 | #include <fstream.hfa> |
2 | #include <kernel.hfa> | |
3 | #include <stdlib.hfa> | |
4 | #include <thread.hfa> | |
[0c92c9f] | 5 | |
[f3c1737] | 6 | thread First { semaphore* lock; }; |
7 | thread Second { semaphore* lock; }; | |
[0c92c9f] | 8 | |
[924c5ce] | 9 | void ?{}( First & this, semaphore & lock ) { ((thread&)this){ "Thread 1" }; this.lock = &lock; } |
10 | void ?{}( Second & this, semaphore & lock ) { ((thread&)this){ "Thread 2" }; this.lock = &lock; } | |
[0c92c9f] | 11 | |
[83a071f9] | 12 | void main(First& this) { |
[0c92c9f] | 13 | for(int i = 0; i < 10; i++) { |
[200fcb3] | 14 | sout | "First : Suspend No." | i + 1; |
[0c92c9f] | 15 | yield(); |
16 | } | |
[4cedd9f] | 17 | V(*this.lock); |
[0c92c9f] | 18 | } |
19 | ||
[83a071f9] | 20 | void main(Second& this) { |
[4cedd9f] | 21 | P(*this.lock); |
[0c92c9f] | 22 | for(int i = 0; i < 10; i++) { |
[200fcb3] | 23 | sout | "Second : Suspend No." | i + 1; |
[0c92c9f] | 24 | yield(); |
25 | } | |
26 | } | |
27 | ||
28 | ||
29 | int main(int argc, char* argv[]) { | |
[f3c1737] | 30 | semaphore lock = { 0 }; |
[200fcb3] | 31 | sout | "User main begin"; |
[0c92c9f] | 32 | { |
[ee897e4b] | 33 | processor p; |
[0c92c9f] | 34 | { |
[83a071f9] | 35 | First f = { lock }; |
36 | Second s = { lock }; | |
[0c92c9f] | 37 | } |
38 | } | |
[200fcb3] | 39 | sout | "User main end"; |
[242a902] | 40 | } |
Note: See TracBrowser
for help on using the repository browser.