I am having problems with deadlocking in my program. So I have been reading about the locks, but the problem is most information is inconsistent or not platform defined. At the Recursive Lock (Mutex) vs Non-Recursive Lock (Mutex) the most accepted answer says:
Because the recursive mutex has a sense of ownership, the thread that grabs the mutex must be the same thread that release the mutex. In the case of non-recursive mutexes, there is no sense of ownership and any thread can usually release the mutex no matter which thread originally took the mutex. In many cases, this type of "mutex" is really more of a semaphore action, where you are not necessarily using the mutex as an exclusion device but use it as synchronization or signaling device between two or more threads.
In the commentaries people say that is not correct and there is no reference about it. So...
1) If I lock a non-recursive mutex in thread A. Can thread B unlock it without grabbing the lock?
2) If in a lock was taken in a Non-Recursive mutex by thread A and thread B calls to get the lock, will thread B wait until the lock has been released to get the lock or will it throw an exception? What about this case in a recursive mutex? (Also discussed in other questions where no decent conclusion could be made)
3) When using recursive locks, on process termination, do all my recursive locks have to be released? (Depending where the process ends that does not happen)
4) What issues am I looking at when using a combination of recursive and non-recursive locks with caution?
PS: Using only windows platform and std::thread
.