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 ead8c7e was
3bb51e1,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Added simple test for monitor
|
-
Property mode set to
100644
|
File size:
644 bytes
|
Rev | Line | |
---|
[3bb51e1] | 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 | enter( &this->m ); |
---|
| 19 | this->value += 1; |
---|
| 20 | leave( &this->m ); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | struct MyThread { thread t; }; |
---|
| 24 | |
---|
| 25 | DECL_THREAD(MyThread); |
---|
| 26 | |
---|
| 27 | void ?{}( MyThread * this ) {} |
---|
| 28 | |
---|
| 29 | void main( MyThread* this ) { |
---|
| 30 | for(int i = 0; i < 1000000; i++) { |
---|
| 31 | increment( &global ); |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | int main(int argc, char* argv[]) { |
---|
| 36 | assert( global.m.entry_queue.tail != NULL ); |
---|
| 37 | processor p; |
---|
| 38 | { |
---|
| 39 | scoped(MyThread) f[4]; |
---|
| 40 | } |
---|
| 41 | sout | global.value | endl; |
---|
| 42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.