57 lines
1.8 KiB
Diff
57 lines
1.8 KiB
Diff
--- tbb-2020.2/oneTBB-2020.2/src/rml/test/test_thread_monitor.cpp 2020-03-30 13:38:06.000000000 +0200
|
|
+++ oneTBB-2020.2/src/rml/test/test_thread_monitor.cpp 2020-04-27 15:43:34.209452298 +0200
|
|
@@ -23,6 +23,7 @@
|
|
#include "thread_monitor.h"
|
|
#include "harness_memory.h"
|
|
#include "tbb/semaphore.cpp"
|
|
+#include <atomic>
|
|
|
|
class ThreadState {
|
|
void loop();
|
|
@@ -33,21 +34,21 @@
|
|
}
|
|
typedef rml::internal::thread_monitor thread_monitor;
|
|
thread_monitor monitor;
|
|
- volatile int request;
|
|
- volatile int ack;
|
|
- volatile unsigned clock;
|
|
- volatile unsigned stamp;
|
|
+ std::atomic<int> request;
|
|
+ std::atomic<int> ack;
|
|
+ std::atomic<unsigned> clock;
|
|
+ unsigned stamp;
|
|
ThreadState() : request(-1), ack(-1), clock(0) {}
|
|
};
|
|
|
|
void ThreadState::loop() {
|
|
for(;;) {
|
|
- ++clock;
|
|
if( ack==request ) {
|
|
thread_monitor::cookie c;
|
|
monitor.prepare_wait(c);
|
|
if( ack==request ) {
|
|
- REMARK("%p: request=%d ack=%d\n", this, request, ack );
|
|
+ REMARK("%p: request=%d ack=%d\n", this, request.load(), ack.load() );
|
|
+ ++clock;
|
|
monitor.commit_wait(c);
|
|
} else
|
|
monitor.cancel_wait();
|
|
@@ -60,7 +61,7 @@
|
|
rml::internal::thread_monitor::yield();
|
|
}
|
|
int r = request;
|
|
- ack = request;
|
|
+ ack = r;
|
|
if( !r ) return;
|
|
}
|
|
}
|
|
@@ -89,7 +90,7 @@
|
|
REPORT("Warning: thread %d not waiting\n",i);
|
|
break;
|
|
}
|
|
- } while( t[i].stamp!=t[i].clock );
|
|
+ } while( t[i].stamp==0 || t[i].stamp!=t[i].clock );
|
|
}
|
|
}
|
|
REMARK("notifying threads\n");
|