[Quickfix-developers] Acceptor thread leaks and race condition cleanup patches
Brought to you by:
orenmnero
From: Gene G. <mus...@ya...> - 2003-04-03 18:26:31
|
1) Acceptor leaks thread in which onRun is running. The code uses incorrect function (the one returning boolean, not threadid) to spawn the onRun thread, and uses resulting "1" instead of correct thread id to join. The consequenses are that accptor->stop (called after onRun) continues running after acceptor.start returns and is acceptor instance gets deleted, which often results in crashes in my server. 2) After fixing above, a race condition in ThreadedSocketAcceptor is apparent. onStop thread iterates over the collection of open connection threads trying to join them. This loop is protected by mutex. However the connection threads themselves attempt to erase themself from the same collection, and deadlock on the same mutex. The fix is to treat shutdown as the special case and when a m_stop flag is set, skip per-thread cleanup. m_stop has to be protected by a separate mutex. My patch uses a class MtVar(.h) (tested internally on all platforms) which allows to change only the declaration: bool m_stop to MtVar<bool> m_stop and have exact same semantics elsewhere, only in a thread-safe way. Four files are attached (in a zip): patches for Acceptor.cpp, ThreadedSocketAccpeptor.cpp and .h and MtVar.h Gene __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com |