source:
tests/concurrent/monitor.cfa
@
42a99b0
Last change on this file since 42a99b0 was 107b01a, checked in by , 6 years ago | |
---|---|
|
|
File size: 661 bytes |
Rev | Line | |
---|---|---|
[73abe95] | 1 | #include <fstream.hfa> |
2 | #include <kernel.hfa> | |
3 | #include <monitor.hfa> | |
4 | #include <thread.hfa> | |
[3bb51e1] | 5 | |
[bcda04c] | 6 | monitor global_t { |
[3bb51e1] | 7 | int value; |
8 | }; | |
9 | ||
[242a902] | 10 | void ?{}(global_t & this) { |
11 | this.value = 0; | |
[3bb51e1] | 12 | } |
13 | ||
14 | static global_t global; | |
15 | ||
[83a071f9] | 16 | void increment3( global_t & mutex this ) { |
17 | this.value += 1; | |
[ef42b143] | 18 | } |
19 | ||
[83a071f9] | 20 | void increment2( global_t & mutex this ) { |
[ef42b143] | 21 | increment3( this ); |
22 | } | |
23 | ||
[83a071f9] | 24 | void increment( global_t & mutex this ) { |
[ef42b143] | 25 | increment2( this ); |
[3bb51e1] | 26 | } |
27 | ||
[bd4d011] | 28 | thread MyThread {}; |
[3bb51e1] | 29 | |
[83a071f9] | 30 | void main( MyThread & this ) { |
[cb0e6de] | 31 | for(int i = 0; i < 1_000_000; i++) { |
[83a071f9] | 32 | increment( global ); |
[3bb51e1] | 33 | } |
34 | } | |
35 | ||
36 | int main(int argc, char* argv[]) { | |
[bcda04c] | 37 | assert( global.__mon.entry_queue.tail != NULL ); |
[3bb51e1] | 38 | processor p; |
39 | { | |
[bd4d011] | 40 | MyThread f[4]; |
[3bb51e1] | 41 | } |
[200fcb3] | 42 | sout | global.value; |
[242a902] | 43 | } |
Note: See TracBrowser
for help on using the repository browser.