ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change
on this file since 1894e03 was
237df76,
checked in by Peter A. Buhr <pabuhr@…>, 3 years ago
|
convert from test programs I/O acquire to mutex statement
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[976bc68] | 1 | #include <fstream.hfa> |
---|
| 2 | #include <locks.hfa> |
---|
| 3 | #include <thread.hfa> |
---|
[237df76] | 4 | #include <mutex_stmt.hfa> |
---|
[976bc68] | 5 | |
---|
| 6 | enum { num_blockers = 17, num_unblockers = 13 }; |
---|
| 7 | |
---|
| 8 | void thrash() { |
---|
| 9 | unsigned t[100]; |
---|
| 10 | for(i; 100) { |
---|
| 11 | t[i] = 0xDEADBEEF; |
---|
| 12 | } |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | ThreadBenaphore ben; |
---|
| 16 | |
---|
| 17 | // const unsigned int num_blocks = 25000; |
---|
| 18 | const unsigned int num_blocks = 5; |
---|
| 19 | |
---|
| 20 | thread Blocker { |
---|
| 21 | size_t sum; |
---|
| 22 | }; |
---|
| 23 | |
---|
| 24 | void main(Blocker & this) { |
---|
[8f1a99e] | 25 | thread$ * me = active_thread(); |
---|
[976bc68] | 26 | this.sum = 0; |
---|
| 27 | for(num_blocks) { |
---|
| 28 | this.sum += (unsigned)me; |
---|
| 29 | thrash(); |
---|
| 30 | P(ben); |
---|
[237df76] | 31 | if(((thread&)this).seqable.next != 0p) mutex(sout) sout | "Link not invalidated"; |
---|
[976bc68] | 32 | thrash(); |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | thread Unblocker { |
---|
| 37 | size_t sum; |
---|
| 38 | }; |
---|
| 39 | |
---|
| 40 | void main(Unblocker & this) { |
---|
| 41 | this.sum = 0; |
---|
| 42 | LOOP: for() { |
---|
| 43 | waitfor( ^?{} : this) { |
---|
| 44 | break LOOP; |
---|
| 45 | } |
---|
| 46 | or else {} |
---|
| 47 | |
---|
[8f1a99e] | 48 | thread$ * t = V(ben, false); |
---|
[976bc68] | 49 | if(t) { |
---|
| 50 | this.sum += (unsigned)t; |
---|
| 51 | unpark(t); |
---|
| 52 | } |
---|
| 53 | yield(random(10)); |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | int main() { |
---|
| 58 | size_t usum = 0; |
---|
| 59 | size_t bsum = 0; |
---|
| 60 | |
---|
| 61 | sout | "Starting"; |
---|
| 62 | { |
---|
| 63 | Blocker blockers [num_blockers ]; |
---|
| 64 | Unblocker unblockers[num_unblockers]; |
---|
| 65 | |
---|
| 66 | for(i;num_blockers) { |
---|
| 67 | bsum += join(blockers[i]).sum; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | sout | "Done!"; |
---|
| 71 | |
---|
| 72 | for(i;num_unblockers) { |
---|
| 73 | usum += join(unblockers[i]).sum; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | if(bsum == usum) sout | "Match!"; |
---|
| 77 | else sout | "No Match!" | usum | "!=" | bsum; |
---|
[237df76] | 78 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.