Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix race condition in thread initialization
The initialization of the data was not done under the same lock as thread
creation.
  • Loading branch information
markus456 committed Aug 27, 2018
1 parent dbaf0be commit f156fb0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions maxscale-cdc-adapter/src/mxs_adapter.cpp
Expand Up @@ -697,6 +697,7 @@ void streamTable(std::string database, std::string table)

int main(int argc, char *argv[])
{
std::unique_lock<std::mutex> guard(ctx_lock);
set_thread_id("main");
configureSignalHandlers(signalHandler);
config = Config::process(argc, argv);
Expand All @@ -723,13 +724,14 @@ int main(int argc, char *argv[])
}

debug("Started %lu threads", threads.size());
guard.unlock();

// Wait until a terminate signal is received
wait_for_signal();

debug("Signal received, stopping");

ctx_lock.lock();
guard.lock();

for (auto&& a : contexts)
{
Expand All @@ -739,7 +741,7 @@ int main(int argc, char *argv[])
a->cdc.close();
}

ctx_lock.unlock();
guard.unlock();

for (auto&& a : threads)
{
Expand Down

0 comments on commit f156fb0

Please sign in to comment.