This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++14 status.

2091. Misplaced effect in m.try_lock_for()

Section: 33.6.4.3 [thread.timedmutex.requirements] Status: C++14 Submitter: Pete Becker Opened: 2011-10-18 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [thread.timedmutex.requirements].

View all issues with C++14 status.

Discussion:

33.6.4.3 [thread.timedmutex.requirements]/4 says, in part,

"Requires: If the tick period of [the argument] is not exactly convertible … [it] shall be rounded up …"

This doesn't belong in the requires clause. It's an effect. It belongs in paragraph 5. Nitpickingly, this would be a technical change: as written it imposes an obligation on the caller, while moving it imposes an obligation on the callee. Although that's certainly not what was intended.

Peter Dimov comments:

Not to mention that it should round down, not up. :-)

Incidentally, I see that the wrong try_lock requirement that the caller shall not own the mutex has entered the standard, after all. Oh well. Let's hope that the real world continues to ignore it.

[2012, Kona]

Remove the offending sentence from the requirements clause. Do not add it back anywhere else. The implementation already must have license to wake up late, so the rounding is invisible.

Move to Review.

[2012, Portland]

Concurrency move to Ready.

[2013-04-20 Bristol]

Proposed resolution:

This wording is relative to N3337.

  1. Change 33.6.4.3 [thread.timedmutex.requirements]/4 as indicated:

    -3- The expression m.try_lock_for(rel_time) shall be well-formed and have the following semantics:

    -4- Requires: If the tick period of rel_time is not exactly convertible to the native tick period, the duration shall be rounded up to the nearest native tick period. If m is of type std::timed_mutex, the calling thread does not own the mutex.