[Quickfix-developers] 1.2.1 ThreadedSocketAcceptor synchronization suggestion
Brought to you by:
orenmnero
From: Gene G. <mus...@ya...> - 2002-09-04 18:58:47
|
I am looking at the ThreadedSocketAcceptor class, and I have noticed that although onStop will likely to run while onStart is looping, the access to m_stop is not guarded. One way to quick fix this (ha) to use an mt_var class : //T must be copyable template<class T> class mt_var { public: mt_var(const T &out) : m_val(x) {} void operator= (const T &in) { locker lock(m_mutex); m_val = in; } operator T () { locker lock(m_mutex); return m_val; } protected: mutex m_mutex; T m_val; }; In that case the only change required in the code in question would be change bool m_stop; to mt_var<bool> m_stop; Of course shutting down m_socket while accepting in another thread is also prone to race conditions, but in the OS that I use Quickfix (Win/Linux) the code works OK. I usually prefer a portable solution by locally connecting to the socket and sending a shutdown message. Of course one could also use non-blocking poll/select with timeout. Gene Gorokhovsky __________________________________________________ Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes http://finance.yahoo.com |