Using Mutex's

G

Guest

Am I right to assume that you use Mutex(s) for protecting shared data within threads of an application; i.e. its not used to protect shared data between separate applications

I have tried to use named Mutex's to protect shared data between two separate applications, but not clear how/where to create the Mutex's. If I create the Mutex once in the InitDialog() routine in each application then I never return from a WaitForSIngleObject(), or if I do via setting a timeout I get error 6

However if I create the Mutex each time before doing the WaitForSIngleObject(), I get ownership of it, but wonder if I am protecting the shared data

Any comment

Graham.
 
J

Jon Skeet [C# MVP]

Graham said:
Am I right to assume that you use Mutex(s) for protecting shared data
within threads of an application; i.e. its not used to protect shared
data between separate applications!

No. Mutexes can span processes.
I have tried to use named Mutex's to protect shared data between two
separate applications, but not clear how/where to create the Mutex's.
If I create the Mutex once in the InitDialog() routine in each
application then I never return from a WaitForSIngleObject(), or if I
do via setting a timeout I get error 6.

However if I create the Mutex each time before doing the
WaitForSIngleObject(), I get ownership of it, but wonder if I am
protecting the shared data.

I would use monitors for blocking within threads - see
System.Threading.Monitor.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top