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 4868be4 was
51f3798,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Added raii guard for monitors
|
-
Property mode set to
100644
|
File size:
637 bytes
|
Line | |
---|
1 | #include <fstream> |
---|
2 | #include <kernel> |
---|
3 | #include <monitor> |
---|
4 | #include <threads> |
---|
5 | |
---|
6 | struct global_t { |
---|
7 | int value; |
---|
8 | monitor m; |
---|
9 | }; |
---|
10 | |
---|
11 | void ?{}(global_t * this) { |
---|
12 | this->value = 0; |
---|
13 | } |
---|
14 | |
---|
15 | static global_t global; |
---|
16 | |
---|
17 | void increment( /*mutex*/ global_t * this ) { |
---|
18 | monitor_guard g = { &this->m }; |
---|
19 | this->value += 1; |
---|
20 | } |
---|
21 | |
---|
22 | struct MyThread { thread t; }; |
---|
23 | |
---|
24 | DECL_THREAD(MyThread); |
---|
25 | |
---|
26 | void ?{}( MyThread * this ) {} |
---|
27 | |
---|
28 | void main( MyThread* this ) { |
---|
29 | for(int i = 0; i < 1000000; i++) { |
---|
30 | increment( &global ); |
---|
31 | } |
---|
32 | } |
---|
33 | |
---|
34 | int main(int argc, char* argv[]) { |
---|
35 | assert( global.m.entry_queue.tail != NULL ); |
---|
36 | processor p; |
---|
37 | { |
---|
38 | scoped(MyThread) f[4]; |
---|
39 | } |
---|
40 | sout | global.value | endl; |
---|
41 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.