473,666 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why are is Mutex owned when requested not to be

Hi All,

The first parameter on the System.Threadin g.Mutex constructor is a
Boolean called initiallyOwned that, according to the documentation,
will give the calling thread ownership if it is true. This leads me
to believe that if false is specified then the calling thread would
not be given ownership. However, the following code indicates that
the calling thread is granted ownership regardless of the
initiallyOwned parameter value.

bool createdNew;
using(Mutex mutex = new Mutex(
false, COMMON_MUTEX_NA ME, out createdNew))
{
// This is surprisingly true since
// the initiallyOwned parameter is false.
Assert.IsTrue(c reatedNew, "The mutex is not owned initially");
}

By the way, according to the documentation, the createdNew flag
indicates the initial owernship.
"contains a Boolean that is true if the "
"calling thread was granted initial ownership"
"of the mutex; otherwise, false"
In other words, this code indicates that the created Mutex is always
owned by the calling thred regardless of the initiallyOwned parameter
value. Any ideas why?

Thanks!
Jul 21 '05 #1
0 1166

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

Similar topics

1
2242
by: Rocky | last post by:
I am using the following piece of code to ensure that my application only runs once, however I have a few questions about it. static Mutex m_Mutex; << in c# I assume that when the methods are static, so are the private members public static void Run(Form mainForm) { if(IsFirstInstance()) {
1
1378
by: Richard Hollis | last post by:
I have a site which is using caching for some frequently used pages. When the page-level cache expires, or is expired by me, the page will get re-rendered to a static HTML file and then shown to the user, after it has been rendered. Assume the cache is stale. Somebody comes along and requests the page. It will then get re-generated, but whilst this is happening, if somebody comes along and requests the page again then they can get an...
4
1390
by: jcrouse | last post by:
I have searched this board for an example and also read Cor's link to the Google thread. I have an application with a startup module called mStartup. My application, after compiled is called CPViewer.exe Here is the code from the Sub Main: Dim owned As Boolea Dim mut As New System.Threading.Mutex(True, "CPViewer.exe", owned Sub main( If owned The Application.Run(New frmVertical mut.ReleaseMutex( Els
8
5509
by: Chris | last post by:
I have an app that is run periodically using Winsows Scheduled Tasks. Occasionally, the app will still be running by the time the scheduled task rolls around again. I don't want the task scheduler to start another instance of my app, but instead check for an existing instance. If there is already an instance of the app running, then I want the second instance to signal the first and then exit. I know I can use a mutex to check for an...
0
201
by: Stuart M. Ray | last post by:
Hi All, The first parameter on the System.Threading.Mutex constructor is a Boolean called initiallyOwned that, according to the documentation, will give the calling thread ownership if it is true. This leads me to believe that if false is specified then the calling thread would not be given ownership. However, the following code indicates that the calling thread is granted ownership regardless of the initiallyOwned parameter value.
4
1242
by: m_palmer45 | last post by:
Hi, I was looking at the code in the standard lib's mutex.py, which is used for queuing function calls. Here is how it lets you acquire a lock: def testandset(self): """Atomic test-and-set -- grab the lock if it is not set, return True if it succeeded.""" if not self.locked: self.locked = 1
3
5548
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock the mutex in order to activate the thread once the data is generated. I have to do it this way, i can only call the thread if the data are generated. ******************************************************** step 1: initialize the mutex
11
3683
by: Lamont Sanford | last post by:
Given an object of type Mutex, what method or property should be called to determine if it is currently owned? I could call WaitOne(0,false) -- and if the return value is false, I could deduce that the Mutex is already owned... but this has the unwanted side effect of seizing ownership of the Mutex in the case where the Mutex is NOT already owned. I'm looking for something like an "IsOwned" property.
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6192
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.