source: src/tests/monitor.c @ 6ce9f7c7

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 6ce9f7c7 was 51f3798, checked in by Thierry Delisle <tdelisle@…>, 7 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.