Are P1,2,3 actually processes or threads in the same app?
Here is how you might approach it using one mutex to protext both R1 and R2.
// Create Mutex in first P.
Mutex m = new Mutex(false, "mymutex");
// P1,2,3 will get existing mutex and wait on it (timeout recommended), do
work, and release it.
Mutex m1 = Mutex.OpenExisting("mymutex");
m1.WaitOne();
// Use R1 and R2.
m1.ReleaseMutex();
--
William Stacey [MVP]
| Hi William,
| thanks for replying, the requirement is:
| 1. there's 2 resources (R1 & R2), which need to be accessed in a serial
| mode
| 2. access to this resources is coming from 3 different multithreaded
| process (P1, P2, P3).
| I try to solve this requirement by using mutexes,
| P1 using the R1, it locked this resources, so R1 can't be used until P1
| is releasing R1.
| The question is: by using Mutex.WaitAny for queueing P1, P2, P3
| accessing R1 & R2, I can't find out whether R1 or R2 is used, so I
| don't know which Mutex to be released. If this kind of requirement
| can't be solved by using mutexes, any other brief solution is highly
| appreciated.
|
| Best Regards,
|