diff options
author | jackpoz <giacomopoz@gmail.com> | 2013-09-01 18:49:49 +0200 |
---|---|---|
committer | jackpoz <giacomopoz@gmail.com> | 2013-09-01 18:49:49 +0200 |
commit | e1e1067d172f9b1a6ba770ca6ae53a07dbc9d56f (patch) | |
tree | c4538f06a9b2c110efbfdb596024a81dbd078483 /src/server/worldserver/Master.cpp | |
parent | 1501e958767ab0cddc5d501796fdcb63bf98a87c (diff) |
Core/Thread: Fix race condition in FreezeDetectorRunnable
Fix race condition by replacing a static volatile uint32 with proper atomic thread-safe ACE_Atomic_Op<ACE_Thread_Mutex, uint32>, 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)
Diffstat (limited to 'src/server/worldserver/Master.cpp')
-rw-r--r-- | src/server/worldserver/Master.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
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) |