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