2020-04-27 14:28:36 +00:00
|
|
|
--- 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 @@
|
2019-08-27 20:31:01 +00:00
|
|
|
}
|
|
|
|
typedef rml::internal::thread_monitor thread_monitor;
|
|
|
|
thread_monitor monitor;
|
|
|
|
- volatile int request;
|
|
|
|
- volatile int ack;
|
|
|
|
- volatile unsigned clock;
|
|
|
|
- volatile unsigned stamp;
|
2020-04-27 14:28:36 +00:00
|
|
|
+ std::atomic<int> request;
|
|
|
|
+ std::atomic<int> ack;
|
|
|
|
+ std::atomic<unsigned> clock;
|
2019-08-27 20:31:01 +00:00
|
|
|
+ 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 ) {
|
2020-04-27 14:28:36 +00:00
|
|
|
- REMARK("%p: request=%d ack=%d\n", this, request, ack );
|
|
|
|
+ REMARK("%p: request=%d ack=%d\n", this, request.load(), ack.load() );
|
2019-08-27 20:31:01 +00:00
|
|
|
+ ++clock;
|
|
|
|
monitor.commit_wait(c);
|
|
|
|
} else
|
|
|
|
monitor.cancel_wait();
|
2020-04-27 14:28:36 +00:00
|
|
|
@@ -60,7 +61,7 @@
|
2019-08-27 20:31:01 +00:00
|
|
|
rml::internal::thread_monitor::yield();
|
|
|
|
}
|
|
|
|
int r = request;
|
|
|
|
- ack = request;
|
|
|
|
+ ack = r;
|
|
|
|
if( !r ) return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-27 14:28:36 +00:00
|
|
|
@@ -89,7 +90,7 @@
|
2019-08-27 20:31:01 +00:00
|
|
|
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");
|