Using Mutex's

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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.
 
Back
Top