source: src/tests/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: 817 bytes
RevLine 
[3bb51e1]1#include <fstream>
2#include <kernel>
3#include <monitor>
[4a3334cf]4#include <thread>
[3bb51e1]5
6struct global_t {
7 int value;
[84c52a8]8 monitor_desc m;
[3bb51e1]9};
10
11void ?{}(global_t * this) {
12 this->value = 0;
13}
14
[ef42b143]15monitor_desc * get_monitor( global_t * this ) {
16 return &this->m;
17}
18
[3bb51e1]19static global_t global;
20
[ef42b143]21void increment3( global_t * mutex this ) {
22 this->value += 1;
23}
24
25void increment2( global_t * mutex this ) {
26 increment3( this );
27}
28
29void increment( global_t * mutex this ) {
30 increment2( this );
[3bb51e1]31}
32
[17af7d1]33struct MyThread { thread_desc __thrd; };
[3bb51e1]34
35DECL_THREAD(MyThread);
36
37void ?{}( MyThread * this ) {}
38
39void main( MyThread* this ) {
40 for(int i = 0; i < 1000000; i++) {
41 increment( &global );
42 }
43}
44
45int main(int argc, char* argv[]) {
46 assert( global.m.entry_queue.tail != NULL );
47 processor p;
48 {
49 scoped(MyThread) f[4];
50 }
51 sout | global.value | endl;
52}
Note: See TracBrowser for help on using the repository browser.