Hello, i have some questions regarding the multithreaded development
1. Lets have 2 threads that are accessing a queue, which is protected by mutex.
Is it necessary to use the same mutex or we can use one mutex for one thread and another mutex for the other thread?
If both threads are trying to access the queue, which is protected by one mutex, what happens? Does one of the threads blocks until the mutex is unlocked or the resource is directly accessed by both threads (which I think leads to data race)? If one of the threads is block, while waiting for the mutex can't we use 2 different mutexes, which would lead to the same result (not very practical, though).
2. We have one thread that is protecting a queue by mutex
What happens if we use second mutex to protect the queue, while the first mutex is already locked? Is this meaningful at all?
Generally my questions is do we always have to use only one mutex to protect single resource or we can use other mutexes?
↧