Morgan Stanley Interview Question
"OS releases mutex by itself" - if possible can you provide a reference.
And "WaitForSigleObject" looks like a windows based function, we prefer something that works for unix/linux, (windows hides a lot of details).
Thanks
Yes, right, it is WinAPI`s function.
From msdn: "If a thread terminates without releasing its ownership of a mutex object, the mutex object is considered to be abandoned. A waiting thread can acquire ownership of an abandoned mutex object, but the wait function will return WAIT_ABANDONED to indicate that the mutex object is abandoned."
Can`t tell how it`s gonna be for linux
A robust mutex can be used to handle the case where the owner of the mutex is terminated while holding the mutex lock, so that a deadlock does not occur. These have more overhead than a regular mutex, and require that all clients locking the mutex be prepared to handle the error code EOWNERDEAD. This indicates that the former owner has died and that the client receiving this error code is the new owner and is responsible for cleaning up any inconsistent state.
A robust mutex is a mutex with the robust attribute set. On Linux this can be set using pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP), or using the POSIX standard function pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST) if you have glibc 2.12 or later (this function was standardized in POSIX.1-2008).
For primitives` description search wiki. And about mutex: in Windows if thread dies/terminates OS releases mutex by itself and WaitForSigleObject(multiply) function returns WAIT_ABANDONED which means that mutex has been released in unnormal way.
- Anonymous November 19, 2010