source: src/tests/multi-monitor.c@ 7c70089

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 7c70089 was 17af7d1, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Some clean-up of runtime code

  • Property mode set to 100644
File size: 1008 bytes
Line 
1#include <fstream>
2#include <kernel>
3#include <monitor>
4#include <thread>
5
6static int global12, global23, global13;
7
8struct monitor_t {
9 monitor_desc m;
10};
11
12monitor_desc * get_monitor( monitor_t * this ) {
13 return &this->m;
14}
15
16static monitor_t m1, m2, m3;
17
18void increment( monitor_t * mutex p1, monitor_t * mutex p2, int * value ) {
19 *value += 1;
20}
21
22struct MyThread {
23 thread_desc __thrd;
24 int target;
25};
26
27DECL_THREAD(MyThread);
28
29void ?{}( MyThread * this, int target ) {
30 this->target = target;
31}
32
33void main( MyThread* this ) {
34 for(int i = 0; i < 1000000; i++) {
35 choose(this->target) {
36 case 0: increment( &m1, &m2, &global12 );
37 case 1: increment( &m2, &m3, &global23 );
38 case 2: increment( &m1, &m3, &global13 );
39 }
40 }
41}
42
43int main(int argc, char* argv[]) {
44 processor p;
45 {
46 scoped(MyThread) * f[6];
47 for(int i = 0; i < 6; i++) {
48 f[i] = ((scoped(MyThread) *)malloc()){ i % 3 };
49 }
50
51 for(int i = 0; i < 6; i++) {
52 delete( f[i] );
53 }
54 }
55 sout | global12 | global23 | global13 | endl;
56}
Note: See TracBrowser for help on using the repository browser.