ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
with_gc
Last change
on this file since e2b17a4 was 83a071f9, checked in by Rob Schluntz <rschlunt@…>, 8 years ago |
Fix concurrency library, tests, and keywords for references
|
-
Property mode
set to
100644
|
File size:
759 bytes
|
Line | |
---|
1 | #include <fstream>
|
---|
2 | #include <kernel>
|
---|
3 | #include <stdlib>
|
---|
4 | #include <thread>
|
---|
5 |
|
---|
6 | thread First { semaphore* lock; };
|
---|
7 | thread Second { semaphore* lock; };
|
---|
8 |
|
---|
9 | void ?{}( First & this, semaphore & lock ) { this.lock = &lock; }
|
---|
10 | void ?{}( Second & this, semaphore & lock ) { this.lock = &lock; }
|
---|
11 |
|
---|
12 | void main(First& this) {
|
---|
13 | for(int i = 0; i < 10; i++) {
|
---|
14 | sout | "First : Suspend No." | i + 1 | endl;
|
---|
15 | yield();
|
---|
16 | }
|
---|
17 | V(this.lock);
|
---|
18 | }
|
---|
19 |
|
---|
20 | void main(Second& this) {
|
---|
21 | P(this.lock);
|
---|
22 | for(int i = 0; i < 10; i++) {
|
---|
23 | sout | "Second : Suspend No." | i + 1 | endl;
|
---|
24 | yield();
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 | int main(int argc, char* argv[]) {
|
---|
30 | semaphore lock = { 0 };
|
---|
31 | sout | "User main begin" | endl;
|
---|
32 | {
|
---|
33 | processor p;
|
---|
34 | {
|
---|
35 | First f = { lock };
|
---|
36 | Second s = { lock };
|
---|
37 | }
|
---|
38 | }
|
---|
39 | sout | "User main end" | endl;
|
---|
40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.