source: src/tests/monitor.c@ dd020c0

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 dd020c0 was cc7f4b1, checked in by Thierry Delisle <tdelisle@…>, 9 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
Line 
1#include <fstream>
2#include <kernel>
3#include <monitor>
4#include <threads>
5
6struct global_t {
7 int value;
8 __monitor_t m;
9};
10
11void ?{}(global_t * this) {
12 this->value = 0;
13}
14
15static global_t global;
16
17void increment( /*mutex*/ global_t * this ) {
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 }
26}
27
28struct MyThread { thread t; };
29
30DECL_THREAD(MyThread);
31
32void ?{}( MyThread * this ) {}
33
34void main( MyThread* this ) {
35 for(int i = 0; i < 1000000; i++) {
36 increment( &global );
37 }
38}
39
40int 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.