fixed thread bug caused by deleting a thread before it is actually terminated

This commit is contained in:
csoler 2019-05-11 23:43:54 +02:00
parent 6a18e242bb
commit 7b2541e35c
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
3 changed files with 10 additions and 2 deletions

View file

@ -533,6 +533,14 @@ void p3GxsTrans::service_tick()
for(std::map<RsGxsId,MsgSizeCount>::const_iterator it(per_user_statistics.begin());it!=per_user_statistics.end();++it)
std::cerr << " " << it->first << ": " << it->second.count << " " << it->second.size << std::endl;
#endif
// Waiting here is very important because the thread may still be updating its semaphores after setting isDone() to true
// If we delete it during this operation it will corrupt the stack and cause unpredictable errors.
while(mCleanupThread->isRunning())
{
std::cerr << "Waiting for mCleanupThread to terminate..." << std::endl;
rstime::rs_usleep(500*1000);
}
delete mCleanupThread;
mCleanupThread=NULL ;