Skip to content

Commit e7592d8

Browse files
committed
[Offload][NFC] Make sure the thread is not running already
1 parent d7e561b commit e7592d8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

offload/plugins-nextgen/common/include/RPC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct RPCServerTy {
9999
/// Initialize the worker thread to run in the background.
100100
ServerThread(void *Buffers[], plugin::GenericDeviceTy *Devices[],
101101
size_t Length)
102-
: Running(true), NumUsers(0), CV(), Mutex(), Buffers(Buffers, Length),
102+
: Running(false), NumUsers(0), CV(), Mutex(), Buffers(Buffers, Length),
103103
Devices(Devices, Length) {}
104104

105105
~ServerThread() { assert(!Running && "Thread not shut down explicitly\n"); }

offload/plugins-nextgen/common/src/RPC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ static rpc::Status runServer(plugin::GenericDeviceTy &Device, void *Buffer) {
9999
}
100100

101101
void RPCServerTy::ServerThread::startThread() {
102+
assert(!Running.load(std::memory_order_relaxed) &&
103+
"Attempting to start thread that is already running");
104+
Running.store(true, std::memory_order_release);
102105
Worker = std::thread([this]() { run(); });
103106
}
104107

105108
void RPCServerTy::ServerThread::shutDown() {
109+
assert(Running.load(std::memory_order_relaxed) &&
110+
"Attempting to shut down a thread that is not running");
106111
{
107112
std::lock_guard<decltype(Mutex)> Lock(Mutex);
108113
Running.store(false, std::memory_order_release);

0 commit comments

Comments
 (0)