To answer your question about N mutexes: yes, it is really possible. What resources are protected by the mutex is entirely up to you as the user of this mutex.
This leads to the first (stated) part of your question. A mutex alone does not guarantee continuity of flow. All this guarantees is MUTual EXclusion - if thread B tries to lock a mutex that was blocked by thread A, thread B will block (not execute code) until thread A unlocks the mutex.
This means that mutexes can be used to ensure that a thread executes a block of code without interruption; but this only works if all threads follow the same mutex blocking protocol around this block of code. This means that you are responsible for assigning semantics (or values) to each individual mutex and properly observing the semantics in your code.
If you decide that the semantics will be “I have an array a of N data elements and an array m of N mutexes, and access to a[i] can only be done when m[i] locked”, then how it will work.
The need to consistently adhere to the same protocol is that you usually need to encapsulate the mutex and the code / data that it protects in the class in one way or another, so that the external code does not need the protocol details. He just knows: "Name this member function and synchronization will happen automatically." This "automagic" will be the class that implements the protocol accordingly.
Angew source share