C++ Logo

std-discussion

Advanced search

Re: Synchronization of atomic notify and wait

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Mon, 25 Jul 2022 11:43:47 +0200
pon., 25 lip 2022 o 06:37 Ryan Nicholl <exaeta_at_[hidden]> napisaƂ(a):
>
> Wait must observe the state changing from expected to something else to return. It cannot deadlock because the sleep is combined with the check through special system calls like SYS_futex. Kernel either A. guarantees you are able to receive notifications on the wait list THEN checks the value for any changes, or B. does both steps of A in an atomic manner, such that no race is possible. One problem i do see is that Linux cannot implement wait correctly on 64 bit values without futex waitv which is a pretty recent add-on, but I think libatomic authors will find a workaround (I assume), though it might be slightly slower, such as a global lock?
>
>

How its implemented does not matter, it could be that non current real
machine could have this problem.
But this is still a problem in standard as on its own it is still
broken or more accurately not precise enough.

I could implement C++ Abstract Machine simulator, and follow the
standard to the letter, and it could misbehave and deadlock.
There will not be any system calls or cache levels but I still have
100% of what C++ can do.

Another thing is sanitizers, how do they know what code is UB and what
is correct if the standard does not say it?
Most of the bugs found by them could "work fine" on the current CPU.

Received on 2022-07-25 09:43:59