source: src/tests/monitor.c @ cb0e6de

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

Threads now use monitor semantics to wait until completion

  • Property mode set to 100644
File size: 857 bytes
Line 
1#include <fstream>
2#include <kernel>
3#include <monitor>
4#include <thread>
5
6struct global_t {
7        int value;
8        monitor_desc m;
9};
10
11void ?{}(global_t * this) {
12        this->value = 0;
13}
14
15monitor_desc * get_monitor( global_t * this ) {
16        return &this->m;
17}
18
19static global_t global;
20
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 );
31}
32
33struct MyThread { thread_desc __thrd; };
34
35DECL_THREAD(MyThread);
36
37void ?{}( MyThread * this ) {}
38void ^?{}( MyThread * mutex this ) {}
39
40void main( MyThread* this ) {
41        for(int i = 0; i < 1_000_000; i++) {
42                increment( &global );
43        }
44}
45
46int main(int argc, char* argv[]) {
47        assert( global.m.entry_queue.tail != NULL );
48        processor p;
49        {
50                scoped(MyThread) f[4];
51        }
52        sout | global.value | endl;
53}
Note: See TracBrowser for help on using the repository browser.