mutex operations could result in exceptions with the following mutex error codes:
- resource_deadlock_would_occur
- resource_unavailable_try_again
- operation_not_permitted
- device_or_resource_busy
- invalid_argument
I have tried 2 situations:
- a deadlock : which should result in an exception with the
resource_deadlock_would_occur
error code. - trying to lock a mutex twice : which should result in an exception with the
device_or_resource_busy
error code.
Both programs are from Stroustrup's book.
Neither situation results in a exception. Both programs simply end without an exception or error message, perhaps due to a timeout.
Josuttis states that in case of a deadlock, the standard library permits (but doesn't require) an exception to be thrown.
Further, according to this thread, trying to lock a mutex twice might also not cause an exception to be thrown. Evidently, the standard library treats this as "undefined behavior" and leaves it to the implementation to decide.
So, are the other three error codes (resource_unavailable_try_again
, operation_not_permitted
, invalid_argument
) also treated as "undefined behavior"?
If an exception isn't guaranteed in these situations, then how can the program protect itself at run-time, against this error?
I haven't been able to find any online documentation on this aspect, and hence this query.