C++ Logo

std-discussion

Advanced search

Re: Atomic notify may get missed by atomic wait

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Fri, 22 Jul 2022 16:02:47 +0500
On 22/07/2022 15:41, Marcin Jaczewski via Std-Discussion wrote:
> pt., 22 lip 2022 o 03:48 Thiago Macieira via Std-Discussion
> <std-discussion_at_[hidden]> napisaƂ(a):
>>
>> On Thursday, 21 July 2022 10:26:49 PDT zwhconst via Std-Discussion wrote:
>>> So it seems to me that the current wording does not guarantee the
>>> termination
>>> of the above code, so as the original code in the other mailing thread.
>>
>> Then please write a paper to firm the wording up.
>>
>
> But what should be added to fix it?
> Would be enough text like:
> "notify guarantee that current value is visible in all threads before
> unblocking"
>
> Will this be a correct solution?

How about: the unblock https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#30.3 (not load!!!) reads the value stored by the latest Y happening before the notify (https://timsong-cpp.github.io/cppwp/n4861/atomics.wait#def:eligible_to_be_unblocked)

This will force coherence-order without forcing synchronizes-with relation (which would have made load(relaxed) optimization useless).

One thing I do not like is that coherence-ordered (https://timsong-cpp.github.io/cppwp/n4861/atomics.order#def:coherence-ordered_before) is about atomic operations, so the thread unblock will have to be somehow squeezed in there.

Received on 2022-07-22 11:02:53