From e1e1067d172f9b1a6ba770ca6ae53a07dbc9d56f Mon Sep 17 00:00:00 2001 From: jackpoz Date: Sun, 1 Sep 2013 18:49:49 +0200 Subject: Core/Thread: Fix race condition in FreezeDetectorRunnable Fix race condition by replacing a static volatile uint32 with proper atomic thread-safe ACE_Atomic_Op, incremented in WorldRunnable::run() at each world loop and read in FreezeDetectorRunnable::run(). Helgrind log: Possible data race during read of size 4 at 0x2400D54 by thread #12 Locks held: none at 0x100FEA6: FreezeDetectorRunnable::run() (Master.cpp:106) by 0x1637892: ACE_Based::Thread::ThreadTask(void*) (Threading.cpp:186) by 0x518F555: ACE_OS_Thread_Adapter::invoke() (OS_Thread_Adapter.cpp:103) by 0x4C2B5AD: mythread_wrapper (hg_intercepts.c:219) by 0x61DAB4F: start_thread (pthread_create.c:304) by 0x6C69A7C: clone (clone.S:112) This conflicts with a previous write of size 4 by thread #9 Locks held: none at 0x100C23E: WorldRunnable::run() (WorldRunnable.cpp:55) by 0x1637892: ACE_Based::Thread::ThreadTask(void*) (Threading.cpp:186) by 0x518F555: ACE_OS_Thread_Adapter::invoke() (OS_Thread_Adapter.cpp:103) by 0x4C2B5AD: mythread_wrapper (hg_intercepts.c:219) by 0x61DAB4F: start_thread (pthread_create.c:304) by 0x6C69A7C: clone (clone.S:112) --- src/server/worldserver/Master.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/server/worldserver/Master.cpp') diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp index b2a6b60ac4f..d9b97cfd3f5 100644 --- a/src/server/worldserver/Master.cpp +++ b/src/server/worldserver/Master.cpp @@ -103,10 +103,11 @@ public: ACE_Based::Thread::Sleep(1000); uint32 curtime = getMSTime(); // normal work - if (_loops != World::m_worldLoopCounter) + uint32 worldLoopCounter = World::m_worldLoopCounter.value(); + if (_loops != worldLoopCounter) { _lastChange = curtime; - _loops = World::m_worldLoopCounter; + _loops = worldLoopCounter; } // possible freeze else if (getMSTimeDiff(_lastChange, curtime) > _delaytime) -- cgit v1.2.3