Groups | Blog | Home
all groups > c# > february 2004 >

c# : Mutex question



Michael A. Covington
2/17/2004 9:33:16 PM
What is the difference between

myMutex.WaitOne(n,false);

and

myMutex.WaitOne(n,true);

where n is a number of milliseconds and myMutex is a Mutex?

The second parameter supposedly says whether to "exit the synchronization
domain before waiting." What does that mean?

Also, can anyone tell me anything about naming of named mutexes? I
understand "Local\\" at the beginning of the name means something, but I
haven't found where this is documented.

Many thanks!

--

Michael A. Covington - Artificial Intelligence Ctr - University of Georgia

"In the core C# language it is simply not possible to have an uninitialized
variable, a 'dangling' pointer, or an expression that indexes an array
beyond its bounds. Whole categories of bugs that routinely plague C and C++
programs are thus eliminated." - A. Hejlsberg, The C# Programming Language

Richard A. Lowe
2/18/2004 12:45:27 AM
Hi Michael, as I understand it you would have to specify a synchronized
context via a SynchronizationAttribute (the one from
System.Runtime.Remoting.Contexts NOT EnterpriseServices) and a class derived
from ContextBoundObject for there to be any difference in behaviour with
this parameter. If you are using the latter, setting it to 'true' will
prevent deadlocks by allowing other threads into the context before you gain
the WaitSleepJoin state.

It's not perfectly clear to me, though, since I've never implemented it. I
doubt many will since .NET Contexts are not terribly well documented and
their uses not well understood (I include myself in that last statement as
well).

Other than the Mutex's name being global, I don't know of any special
behaviour vis-a-vis certain naming conventions so I can't help you there.

Richard

--
C#, .NET and (a bit of) Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
[quoted text, click to view]

Dave
2/18/2004 3:41:10 AM
[quoted text, click to view]

Naming a mutex allows it to be used for cross-process synchronization -
unnamed mutexes are only visible within the owning process. There are no
user-mode requirements or conventions regarding mutex names other then to
name them so they are unique otherwise you may inadvertently step on one
that is in use. The Win32 kernel mode device manager has some conventions it
follows when it creates them but it's been a while and I don't remember the
details and it's nothing that affects anything in user mode.

Stephen Martin
2/18/2004 6:37:49 AM
The Local\ and Global\ prefixes are used to determine the scope of the name
when used in Terminal Services sessions. Local\ creates an object that is
valid in that session only and Global\ creates an object visible in all
sessions. Check out:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termserv/kernel_object_namespaces.asp


[quoted text, click to view]

Michael A. Covington
2/18/2004 10:01:10 PM
Thanks.

Next question: Is there a debugging tool that will show me the operating
system's whole list of named mutexes and which process owns which one?

Chad Z. Hower aka Kudzu
2/19/2004 10:30:15 AM
[quoted text, click to view]

try www.sysinternals.com - likely something there.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
AddThis Social Bookmark Button