ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since df40a56 was
3381ed7,
checked in by Thierry Delisle <tdelisle@…>, 5 years ago
|
Added park/unpark primitives thread and removed BlockInternal?.
Converted monitors to use park unpark.
Intrusive Queue now mark next field when thread is inside queue.
Added several asserts to kernel and monitor.
Added a few tests for park and unpark.
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[73abe95] | 1 | #include <fstream.hfa> |
---|
| 2 | #include <kernel.hfa> |
---|
| 3 | #include <monitor.hfa> |
---|
| 4 | #include <thread.hfa> |
---|
[2781e65] | 5 | |
---|
| 6 | static int global12, global23, global13; |
---|
| 7 | |
---|
[bcda04c] | 8 | monitor monitor_t {}; |
---|
[ef42b143] | 9 | |
---|
| 10 | static monitor_t m1, m2, m3; |
---|
[2781e65] | 11 | |
---|
[83a071f9] | 12 | void increment( monitor_t & mutex p1, monitor_t & mutex p2, int & value ) { |
---|
[3381ed7] | 13 | assert(active_thread() == get_monitor(p1)->owner); |
---|
| 14 | assert(active_thread() == get_monitor(p2)->owner); |
---|
[83a071f9] | 15 | value += 1; |
---|
[3381ed7] | 16 | assert(active_thread() == get_monitor(p1)->owner); |
---|
| 17 | assert(active_thread() == get_monitor(p2)->owner); |
---|
[2781e65] | 18 | } |
---|
| 19 | |
---|
[83a071f9] | 20 | thread MyThread { |
---|
[2781e65] | 21 | int target; |
---|
| 22 | }; |
---|
| 23 | |
---|
[00e80b6] | 24 | void ?{}( MyThread & this, int target ) { |
---|
| 25 | this.target = target; |
---|
[2781e65] | 26 | } |
---|
| 27 | |
---|
[00e80b6] | 28 | void ^?{}( MyThread & mutex this ) {} |
---|
[cb0e6de] | 29 | |
---|
[83a071f9] | 30 | void main( MyThread & this ) { |
---|
[2781e65] | 31 | for(int i = 0; i < 1000000; i++) { |
---|
[83a071f9] | 32 | choose(this.target) { |
---|
| 33 | case 0: increment( m1, m2, global12 ); |
---|
| 34 | case 1: increment( m2, m3, global23 ); |
---|
| 35 | case 2: increment( m1, m3, global13 ); |
---|
[2781e65] | 36 | } |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
[83a071f9] | 40 | forall(dtype T | sized(T) | { void ^?{}(T & mutex); }) |
---|
| 41 | void delete_mutex(T * x) { |
---|
| 42 | ^(*x){}; |
---|
| 43 | free(x); |
---|
| 44 | } |
---|
| 45 | |
---|
[2781e65] | 46 | int main(int argc, char* argv[]) { |
---|
| 47 | processor p; |
---|
| 48 | { |
---|
[83a071f9] | 49 | MyThread * f[6]; |
---|
[2781e65] | 50 | for(int i = 0; i < 6; i++) { |
---|
[83a071f9] | 51 | f[i] = new(i % 3); |
---|
[2781e65] | 52 | } |
---|
| 53 | |
---|
| 54 | for(int i = 0; i < 6; i++) { |
---|
[83a071f9] | 55 | delete_mutex( f[i] ); |
---|
[2781e65] | 56 | } |
---|
| 57 | } |
---|
[200fcb3] | 58 | sout | global12 | global23 | global13; |
---|
[00e80b6] | 59 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.