Date: Tue, 19 Jul 2022 13:01:13 +0500
On 19/07/2022 12:30, Andrey Semashev via Std-Discussion wrote:
> On 7/19/22 09:58, language.lawyer_at_[hidden] wrote:
>> On 19/07/2022 11:43, Andrey Semashev via Std-Discussion wrote:
>>> It means the store happens-before notify_one (in the non-main thread).
>>>
>>> Coherence-ordered before is the relation between the store and the
>>> wait in the two threads.
>>> It says that when the store is coherence-ordered before the wait in
>>> the modification order of the atomic, the wait will observe the
>>> effects of the store.
>>
>> To me, http://eel.is/c++draft/atomics.order#3 reads in the opposite
>> direction. If the wake-up read observes the new value, it will become
>> coherence-ordered before. But if it does not observe, it won't.
>> So, what guarantees it will observe the new value?
>
> If the wait doesn't observe the store, it blocks. And in that case, it
> unblocks when it observes the notify, which happens-after the store. So
> if the wait is unblocked by notify, it must also observe the store on
> the second load.
Yes, the invocation of notify_one happens-after the store in the non-main thread.
notify_one «Unblocks the execution of at least one atomic waiting operation...» (https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#32)
The waiting thread «Blocks until it is unblocked by an atomic notifying operation» (https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#30.3)
So, now, what is the relation between the invocation of notify_one and the unblock of the waiting thread? Does it synchronize-with it? Does https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#30.3 happen-after the invocation of notify_one in any other way? If not, then why https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#30.3 must observe the new value?
> On 7/19/22 09:58, language.lawyer_at_[hidden] wrote:
>> On 19/07/2022 11:43, Andrey Semashev via Std-Discussion wrote:
>>> It means the store happens-before notify_one (in the non-main thread).
>>>
>>> Coherence-ordered before is the relation between the store and the
>>> wait in the two threads.
>>> It says that when the store is coherence-ordered before the wait in
>>> the modification order of the atomic, the wait will observe the
>>> effects of the store.
>>
>> To me, http://eel.is/c++draft/atomics.order#3 reads in the opposite
>> direction. If the wake-up read observes the new value, it will become
>> coherence-ordered before. But if it does not observe, it won't.
>> So, what guarantees it will observe the new value?
>
> If the wait doesn't observe the store, it blocks. And in that case, it
> unblocks when it observes the notify, which happens-after the store. So
> if the wait is unblocked by notify, it must also observe the store on
> the second load.
Yes, the invocation of notify_one happens-after the store in the non-main thread.
notify_one «Unblocks the execution of at least one atomic waiting operation...» (https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#32)
The waiting thread «Blocks until it is unblocked by an atomic notifying operation» (https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#30.3)
So, now, what is the relation between the invocation of notify_one and the unblock of the waiting thread? Does it synchronize-with it? Does https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#30.3 happen-after the invocation of notify_one in any other way? If not, then why https://timsong-cpp.github.io/cppwp/n4861/atomics.types.operations#30.3 must observe the new value?
Received on 2022-07-19 08:01:19