From 28b86ba0a4bf7cf68f51889b2a74ba0463b57da4 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Wed, 16 May 2018 08:32:21 -0700 Subject: [PATCH] fix some tsan issues (thread sanitizer) --- examples/MultiThreading/b3PosixThreadSupport.cpp | 3 ++- examples/SharedMemory/PhysicsServerExample.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/MultiThreading/b3PosixThreadSupport.cpp b/examples/MultiThreading/b3PosixThreadSupport.cpp index dfec90df6..cd5117182 100644 --- a/examples/MultiThreading/b3PosixThreadSupport.cpp +++ b/examples/MultiThreading/b3PosixThreadSupport.cpp @@ -268,7 +268,8 @@ void b3PosixThreadSupport::stopThreads() for(size_t t=0; t < size_t(m_activeThreadStatus.size()); ++t) { b3ThreadStatus& spuStatus = m_activeThreadStatus[t]; - printf("%s: Thread %i used: %ld\n", __FUNCTION__, int(t), spuStatus.threadUsed); + + // printf("%s: Thread %i used: %ld\n", __FUNCTION__, int(t), spuStatus.threadUsed); spuStatus.m_userPtr = 0; checkPThreadFunction(sem_post(spuStatus.startSemaphore)); diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 03a085a34..f4bfbe967 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -260,6 +260,8 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) if (init) { + unsigned int cachedSharedParam = eMotionIsInitialized; + args->m_cs->lock(); args->m_cs->setSharedParam(0,eMotionIsInitialized); args->m_cs->unlock(); @@ -269,6 +271,8 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) int numCmdSinceSleep1ms = 0; unsigned long long int prevTime = clock.getTimeMicroseconds(); + + do { { @@ -468,7 +472,11 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) numCmdSinceSleep1ms++; } - } while (args->m_cs->getSharedParam(0)!=eRequestTerminateMotion); + args->m_cs->lock(); + cachedSharedParam = args->m_cs->getSharedParam(0); + args->m_cs->unlock(); + + } while (cachedSharedParam!=eRequestTerminateMotion); } else { args->m_cs->lock(); @@ -1749,7 +1757,7 @@ void PhysicsServerExample::initPhysics() m_isConnected = m_physicsServer.connectSharedMemory( m_guiHelper); - + for (int i=0;igetNumTasks();i++) {