ADT
ast-experimental
pthread-emulation
qualifiedEnum
|
Last change
on this file since b738974 was 237df76, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago |
|
convert from test programs I/O acquire to mutex statement
|
-
Property mode
set to
100644
|
|
File size:
717 bytes
|
| Line | |
|---|
| 1 | #include <fstream.hfa>
|
|---|
| 2 | #include <thread.hfa>
|
|---|
| 3 | #include <mutex_stmt.hfa>
|
|---|
| 4 | #include <time.hfa>
|
|---|
| 5 |
|
|---|
| 6 | Duration default_preemption() {
|
|---|
| 7 | return 0;
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | volatile int counter = 0;
|
|---|
| 11 |
|
|---|
| 12 | thread fast_sleeper {};
|
|---|
| 13 | void main(fast_sleeper &) {
|
|---|
| 14 | Duration wait = 47`ms;
|
|---|
| 15 | for(i; 20) {
|
|---|
| 16 | sleep(wait);
|
|---|
| 17 | __atomic_fetch_add( &counter, 1, __ATOMIC_RELAXED );
|
|---|
| 18 | }
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | thread slow_sleeper {};
|
|---|
| 22 | void main(slow_sleeper &) {
|
|---|
| 23 | Duration wait = 277`ms;
|
|---|
| 24 | for(i; 4) {
|
|---|
| 25 | sleep(wait);
|
|---|
| 26 | int val = __atomic_add_fetch( &counter, -5, __ATOMIC_RELAXED );
|
|---|
| 27 | if(val < -9) abort | "Value reached negative value:" | val;
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | int main() {
|
|---|
| 32 | mutex( sout ) sout | "start";
|
|---|
| 33 | {
|
|---|
| 34 | slow_sleeper slow;
|
|---|
| 35 | yield();
|
|---|
| 36 | fast_sleeper fast;
|
|---|
| 37 | yield();
|
|---|
| 38 | }
|
|---|
| 39 | mutex( sout ) sout | "done";
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.