Title
Mutex specification questions
Status
dup
Section
[thread.mutex.class]
Submitter
Herb Sutter

Created on 2008-09-18.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Duplicate: 893

Date: 2010-10-21.18:28:33

[ Summit: ]

Two resolutions: "not a defect" and "duplicate", as follows:

  • [thread.mutex.requirements]/24: NAD. If the precondition fails the program has undefined behaviour and therefore an implementation may throw an exception already.
  • [thread.mutex.class]/3 bullet 2: Already addressed by issue 893.
  • [thread.mutex.class]/3 proposed addition: NAD. This is already covered by the mutex requirements, which have ownership as a Precondition.
Date: 2008-09-18.00:00:00

A few questions on the current WP, N2723:

[thread.mutex.requirements]/24 says an expression mut.unlock() "Throws: Nothing." I'm assuming that, per [res.on.required], errors that violate the precondition "The calling thread shall own the mutex" opens the door for throwing an exception anyway, such as to report unbalanced unlock operations and unlocking from a thread that does not have ownership. Right?

[thread.mutex.class]/3 (actually numbered paragraph "27" in the WP; this is just a typo I think) says

The behavior of a program is undefined if:

  • it destroys a mutex object owned by any thread,
  • a thread that owns a mutex object calls lock() or try_lock() on that object, or
  • a thread terminates while owning a mutex object.

As already discussed, I think the second bullet should be removed, and such a lock() or try_lock() should fail with an exception or returning false, respectively.

A potential addition to the list would be

  • a thread unlocks a mutex it does not have ownership of.

but without that the status quo text endorses the technique of the program logically transferring ownership of a mutex to another thread with correctness enforced by programming discipline. Was that intended?

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg4303
2010-10-21 18:28:33adminsetmessages: + msg4302
2008-09-18 00:00:00admincreate