473,382 Members | 1,425 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,382 software developers and data experts.

Why are is Mutex owned when requested not to be

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.

bool createdNew;
using(Mutex mutex = new Mutex(
false, COMMON_MUTEX_NAME, out createdNew))
{
// This is surprisingly true since
// the initiallyOwned parameter is false.
Assert.IsTrue(createdNew, "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 1147

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

Similar topics

1
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...
1
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...
4
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...
8
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...
0
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...
4
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 --...
3
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...
11
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.