I’ve inherited some code like this:
m_mutex.Lock();
ResetEvent( m_hSyncObject );
m_mutex.Unlock();
Same for SetEvent()
Are those Mutexes necessary in this case – do those calls behave themselves or can I get away with removing the locks? This function has already had some inc/decs of values that I made atomic earlier and now just these events are within the locks, so getting rid of them would be a big win if possible.
This extra mutex is almost certainly unneeded. The
ResetEventandSetEventfunctions themselves are safe to call from multiple threadsGiven that this code does exists it seems highly likely that the developer who wrote that code didn’t understand the threading semantics they’d created. I would treat any code depending on that logic as highly suspect. It’d probably save you some time in the long run to go ahead and pre-audit that code for threading issues