Fix name uniqueness check in System.Spawn
Summary: Old code would start reactor thread first, and then try to insert it in unordered_map. If it failed to insert it, the thread handler would get destructed with thread still running, which raises an exception. Reviewers: buda, mislav.bradac Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D956
This commit is contained in:
parent
09ad52958f
commit
0930e8c457
@ -525,15 +525,15 @@ class System : public ChannelFinder {
|
||||
finder = this;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
CHECK(reactors_.find(name) == reactors_.end())
|
||||
<< "Reactor with name: '" << name << "' already exists.";
|
||||
std::unique_ptr<Reactor> reactor(new Reactor(*finder, name, setup));
|
||||
std::thread reactor_thread([reactor = reactor.get()] {
|
||||
reactor->setup_(*reactor);
|
||||
reactor->RunEventLoop();
|
||||
});
|
||||
auto got = reactors_.emplace(
|
||||
name, std::pair<decltype(reactor), std::thread>{
|
||||
std::move(reactor), std::move(reactor_thread)});
|
||||
CHECK(got.second) << "Reactor with name: '" << name << "' already exists";
|
||||
reactors_.emplace(name, std::pair<decltype(reactor), std::thread>{
|
||||
std::move(reactor), std::move(reactor_thread)});
|
||||
}
|
||||
|
||||
std::shared_ptr<ChannelWriter> FindChannel(
|
||||
|
Loading…
Reference in New Issue
Block a user