source:
src/tests/monitor.c
@
bcda04c
Last change on this file since bcda04c was bcda04c, checked in by , 7 years ago | |
---|---|
|
|
File size: 776 bytes |
Rev | Line | |
---|---|---|
[3bb51e1] | 1 | #include <fstream> |
2 | #include <kernel> | |
3 | #include <monitor> | |
[4a3334cf] | 4 | #include <thread> |
[3bb51e1] | 5 | |
[bcda04c] | 6 | monitor global_t { |
[3bb51e1] | 7 | int value; |
8 | }; | |
9 | ||
10 | void ?{}(global_t * this) { | |
11 | this->value = 0; | |
12 | } | |
13 | ||
14 | static global_t global; | |
15 | ||
[ef42b143] | 16 | void increment3( global_t * mutex this ) { |
17 | this->value += 1; | |
18 | } | |
19 | ||
20 | void increment2( global_t * mutex this ) { | |
21 | increment3( this ); | |
22 | } | |
23 | ||
24 | void increment( global_t * mutex this ) { | |
25 | increment2( this ); | |
[3bb51e1] | 26 | } |
27 | ||
[17af7d1] | 28 | struct MyThread { thread_desc __thrd; }; |
[3bb51e1] | 29 | |
30 | DECL_THREAD(MyThread); | |
31 | ||
32 | void ?{}( MyThread * this ) {} | |
[cb0e6de] | 33 | void ^?{}( MyThread * mutex this ) {} |
[3bb51e1] | 34 | |
35 | void main( MyThread* this ) { | |
[cb0e6de] | 36 | for(int i = 0; i < 1_000_000; i++) { |
[3bb51e1] | 37 | increment( &global ); |
38 | } | |
39 | } | |
40 | ||
41 | int main(int argc, char* argv[]) { | |
[bcda04c] | 42 | assert( global.__mon.entry_queue.tail != NULL ); |
[3bb51e1] | 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.