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 1e6b350 was
cc7f4b1,
checked in by Thierry Delisle <tdelisle@…>, 7 years ago
|
- renamed monitor to monitor_t since the type should not be exposed to users
- added support for recursion in monitors
|
-
Property mode set to
100644
|
File size:
735 bytes
|
Rev | Line | |
---|
[3bb51e1] | 1 | #include <fstream> |
---|
| 2 | #include <kernel> |
---|
| 3 | #include <monitor> |
---|
| 4 | #include <threads> |
---|
| 5 | |
---|
| 6 | struct global_t { |
---|
| 7 | int value; |
---|
[cc7f4b1] | 8 | __monitor_t m; |
---|
[3bb51e1] | 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 ) { |
---|
[cc7f4b1] | 18 | monitor_guard_t g1 = { &this->m }; |
---|
| 19 | { |
---|
| 20 | monitor_guard_t g2 = { &this->m }; |
---|
| 21 | { |
---|
| 22 | monitor_guard_t g3 = { &this->m }; |
---|
| 23 | this->value += 1; |
---|
| 24 | } |
---|
| 25 | } |
---|
[3bb51e1] | 26 | } |
---|
| 27 | |
---|
| 28 | struct MyThread { thread t; }; |
---|
| 29 | |
---|
| 30 | DECL_THREAD(MyThread); |
---|
| 31 | |
---|
| 32 | void ?{}( MyThread * this ) {} |
---|
| 33 | |
---|
| 34 | void main( MyThread* this ) { |
---|
| 35 | for(int i = 0; i < 1000000; i++) { |
---|
| 36 | increment( &global ); |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | int main(int argc, char* argv[]) { |
---|
| 41 | assert( global.m.entry_queue.tail != NULL ); |
---|
| 42 | processor p; |
---|
| 43 | { |
---|
| 44 | scoped(MyThread) f[4]; |
---|
| 45 | } |
---|
| 46 | sout | global.value | endl; |
---|
| 47 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.