ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 6dc78dee was
0c92c9f,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Cleaned-up threading code and added temporary test for threads (single core)
|
-
Property mode set to
100644
|
File size:
850 bytes
|
Line | |
---|
1 | #include <fstream> |
---|
2 | #include <kernel> |
---|
3 | #include <stdlib> |
---|
4 | #include <threads> |
---|
5 | |
---|
6 | struct First { thread t; simple_lock* lock; }; |
---|
7 | struct Second { thread t; simple_lock* lock; }; |
---|
8 | |
---|
9 | DECL_THREAD(First) |
---|
10 | DECL_THREAD(Second) |
---|
11 | |
---|
12 | void ?{}( First * this, simple_lock* lock ) { this->lock = lock; } |
---|
13 | void ?{}( Second * this, simple_lock* lock ) { this->lock = lock; } |
---|
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 | } |
---|
20 | unlock(this->lock); |
---|
21 | } |
---|
22 | |
---|
23 | void main(Second* this) { |
---|
24 | lock(this->lock); |
---|
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[]) { |
---|
33 | simple_lock lock; |
---|
34 | sout | "User main begin" | endl; |
---|
35 | { |
---|
36 | // processor p; |
---|
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.