473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Quick Mutex Question

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.
Nov 16 '05 #1
2 986
dln <dn**********@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
dln
Great! Thanks.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
dln <dn**********@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
3
by: smith4894 | last post by:
Hello, I have an application that essentially consists of two threads doing their things. One thread is a producer, and pushes bytes (of a struct) into a pipe, and another is a consumer that...
2
by: dln | last post by:
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()"...
16
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
6
by: Jun Kusanagi | last post by:
Is there any way to solve process synchronization between more than 1 resources. I'm already trying to use Mutex.WaitAny, but I confused to execute Release method from the corresponding mutexes....
2
by: tony.newsgrps | last post by:
Hi there, I'm trying to understand the impact of killing a process that owns a system mutex (used to ensure there is only 1 instance of my program running) Here is my code pretty much: try...
8
by: Dan Pavel | last post by:
Hi, I did not used Mutex before and I need now. I have an application that control some workflows on different machines. I use SNMP for that. The problem is that the thread used for starting an...
1
by: chsalvia | last post by:
I was browsing through the souce code for the boost mutex implementation just to understand how the library works. I get the basic idea: a mutex object is associated with a scoped_lock object....
2
by: Jeroen | last post by:
Hi all, I've been trying to get my head around threading. Here's an example from the book I'm reading: /***************************/ Mutex m = null; const string name = "xyz"; try
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.