mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-29 08:37:36 -04:00
fixed thread bug caused by deleting a thread before it is actually terminated
This commit is contained in:
parent
6a18e242bb
commit
7b2541e35c
3 changed files with 10 additions and 2 deletions
|
@ -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)
|
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;
|
std::cerr << " " << it->first << ": " << it->second.count << " " << it->second.size << std::endl;
|
||||||
#endif
|
#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;
|
delete mCleanupThread;
|
||||||
mCleanupThread=NULL ;
|
mCleanupThread=NULL ;
|
||||||
|
|
|
@ -66,8 +66,8 @@ void RsThread::go()
|
||||||
|
|
||||||
runloop();
|
runloop();
|
||||||
|
|
||||||
mHasStoppedSemaphore.set(1);
|
|
||||||
mShouldStopSemaphore.set(0);
|
mShouldStopSemaphore.set(0);
|
||||||
|
mHasStoppedSemaphore.set(1); // last value that we modify because this is interpreted as a signal that the object can be deleted.
|
||||||
}
|
}
|
||||||
void *RsThread::rsthread_init(void* p)
|
void *RsThread::rsthread_init(void* p)
|
||||||
{
|
{
|
||||||
|
|
|
@ -247,7 +247,7 @@ public:
|
||||||
|
|
||||||
void start(const std::string &threadName = "");
|
void start(const std::string &threadName = "");
|
||||||
|
|
||||||
// Returns true of the thread is still running.
|
// Returns true if the thread is still running.
|
||||||
|
|
||||||
bool isRunning();
|
bool isRunning();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue