I understand the basic principle of mutex's is to protect specific code path from being accessed by more than 1 threads.
In my current setup, I have 10 threads of type A (A1-A10), and 10 threads of type B(B1-B10). By type I mean, threads that are running infinite loop and calling method A() and B() respectively. From these methods A and B, they are both calling a function X().
What I'm trying to do is, lock a certain part of code in function X(), so that at any time from a pair of A and B (A1:B1, A2:B2...) only 1 is accessing that path. Meaning either A1 is in that code path or B1, similarly either A2 is in that code path of B2 and so on. Its fine if A1,A2,B3,B4,A5.. are accessing that code path at the same time. It's just that from a A-B pair there is only 1 thread accessing this code.
How do I implement that?
X() {
//
Lock this code so that either of (A1, B1) can access it
and so on..
//
}