Quick Mutex Question

  • Thread starter Thread starter dln
  • Start date Start date
D

dln

If I were to use the following call:

Mutex my_mutex = new Mutex();
bool got_lock = my_mutex.WaitOne(500, false);

and then got_lock returns false, do I need to call "my_mutex.ReleaseMutex()"
on it? So put another way, should I always call ReleaseMutex, regardless of
whether or not I got the lock?

Thanks.
 
dln said:
If I were to use the following call:

Mutex my_mutex = new Mutex();
bool got_lock = my_mutex.WaitOne(500, false);

and then got_lock returns false, do I need to call "my_mutex.ReleaseMutex()"
on it? So put another way, should I always call ReleaseMutex, regardless of
whether or not I got the lock?

No - if you didn't acquire it, you shouldn't release it.
 
Back
Top