c++ - crash on find() of set container -
I have a SyncSet template class that is locked on the set operation. When I was under stress testing, I had an accident. When I check the crash output file, it seems that there is some reason to find the set container function. You can see your template class below and you can access related crash output in the pastebin link:
Is there something wrong with my template class like this? Secondly, this is an OS cancellation application because there is more than or above the memory limit, is there a way to check the message on the OS (Windows 7 Professional)?
All the advice and comments are good
Thanks.
template & lt; Typename T & gt; Class SyncSet {Public: SyncSet () {Initial Critical Science (& amp; m_lock); } ~ SyncSet () {DeleteCriticalSection (& amp; m_lock); } Insert blank (T'Ems) {EnterCriticalSection (& amp; m_lock); M_set.insert (ELEM); LeaveCriticalSection (& amp; m_lock); } Bool (t ames) {if (m_set.mti ()) m_set.find (amm) == m_set.end () returned incorrectly; Back true; } Bool erase (T elem) {If (! (AMM)) false return; EnterCriticalSection (& amp; m_lock); M_set.erase (ELEM); LeaveCriticalSection (& amp; m_lock); Back true; } Size_t size () {return m_set.size (); } Clear Zero () {EnterCriticalSection (& amp; m_lock); M_set.clear (); LeaveCriticalSection (& amp; m_lock); } Private: std :: set & lt; T & gt; M_set; CRITICAL_SECTION m_lock; };
Your code is not thread-safe, as you all write important sections Set within, you do not protect reading in Haas ().
For example, stress testing can occur on a half way through a hash () call when the other thread wipes the whole set.
Note that a critical_Section is a gate, it is checked only on other EnterCriticalSection () calls, and does not use the address inside it, so the code will not be stopped when the second thread Important section.
Comments
Post a Comment