Skip to content
Snippets Groups Projects
Commit 66dd2739 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

terminate thread in destructor

parent 76ccd519
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,14 @@ namespace ChimeraTK {
: impl(nullptr), _direction(VariableDirection::feeding)
{}
/** The destructor will terminate the internal thread, if running */
~FanOut() {
if(_thread.joinable()) {
requestTerminateThread = true;
_thread.join();
}
}
/** Add a slave to the FanOut. Only sending end-points of a consuming node may be added. */
void addSlave(boost::shared_ptr<mtca4u::ProcessVariable> slave) {
if(!slave->isSender()) {
......@@ -68,6 +76,7 @@ namespace ChimeraTK {
void activate() {
assert(_direction == VariableDirection::consuming);
assert(!_thread.joinable());
_thread = std::thread([this] { this->run(); });
}
......@@ -78,7 +87,10 @@ namespace ChimeraTK {
while(true) {
// wait for external trigger
/// @todo TODO replace with proper blocking implementation when supported by the CSA
while(externalTrigger->receive() == false) std::this_thread::yield();
while(externalTrigger->receive() == false) {
if(requestTerminateThread) return;
std::this_thread::yield();
}
// receive data
impl->receive();
for(auto &slave : slaves) { // send out copies to slaves
......@@ -157,6 +169,9 @@ namespace ChimeraTK {
/** Thread handling the synchronisation, if needed */
std::thread _thread;
/** Flag to request termination of the synchronisation thread. */
bool requestTerminateThread{false};
};
} /* namespace ChimeraTK */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment