source: src/tests/monitor.c @ 3bb51e1

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

Added simple test for monitor

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