source: src/tests/monitor.c@ ef9cc56

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 ef9cc56 was 51f3798, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Added raii guard for monitors

  • Property mode set to 100644
File size: 637 bytes
Line 
1#include <fstream>
2#include <kernel>
3#include <monitor>
4#include <threads>
5
6struct global_t {
7 int value;
8 monitor 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 g = { &this->m };
19 this->value += 1;
20}
21
22struct MyThread { thread t; };
23
24DECL_THREAD(MyThread);
25
26void ?{}( MyThread * this ) {}
27
28void main( MyThread* this ) {
29 for(int i = 0; i < 1000000; i++) {
30 increment( &global );
31 }
32}
33
34int main(int argc, char* argv[]) {
35 assert( global.m.entry_queue.tail != NULL );
36 processor p;
37 {
38 scoped(MyThread) f[4];
39 }
40 sout | global.value | endl;
41}
Note: See TracBrowser for help on using the repository browser.