7
I have the following problem:
A program generates two types of A and B threads through clicks on their respective buttons. The two types cannot run at the same time. If I have 10 A threads, B can only run when the 10 A threads are finished.
I can restrict the input, creating a mutex for each type and a boolean variable that tells me whether or not there are threads of the other type being executed. However, when the first thread is finished, the opposite one can enter the critical region because I am using the nameMutex.Waitone().
How can I adapt the use of 'Waitall' to this situation? I couldn’t quite understand the concept.
In fact, my problem looks more like that of the "Bathroom Unisex". I could say that A and B are men and women trying to use the same "bathroom". If you have A, only A can enter and B waits to empty. If you have B, only B can enter and A waits to empty.
– lys
I understand... in this case the
ReaderWriterLockSlim
does not really serve. I made an implementation using a Mutex, twoManualResetEventSlim
and two accountants. It is not perfect (suffers from starvation), but it is a good start. See if it suits you, and tell me if you have doubt.– Miguel Angelo