source: src/tests/monitor.c @ 348006f

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 348006f was 348006f, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Renamed thread to thread_desc

  • Property mode set to 100644
File size: 760 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
15static global_t global;
16
17void increment( /*mutex*/ global_t * this ) {
[84c52a8]18        monitor_desc * mon = &this->m;
[2781e65]19        monitor_guard_t g1 = { &mon };
[cc7f4b1]20        {
[2781e65]21                monitor_guard_t g2 = { &mon };
[cc7f4b1]22                {
[2781e65]23                        monitor_guard_t g3 = { &mon };
[cc7f4b1]24                        this->value += 1;
25                }
26        }
[3bb51e1]27}
28
[348006f]29struct MyThread { thread_desc t; };
[3bb51e1]30
31DECL_THREAD(MyThread);
32
33void ?{}( MyThread * this ) {}
34
35void main( MyThread* this ) {
36        for(int i = 0; i < 1000000; i++) {
37                increment( &global );
38        }
39}
40
41int main(int argc, char* argv[]) {
42        assert( global.m.entry_queue.tail != NULL );
43        processor p;
44        {
45                scoped(MyThread) f[4];
46        }
47        sout | global.value | endl;
48}
Note: See TracBrowser for help on using the repository browser.