volatile deprecations in c++20
Christian Franke
Christian.Franke@t-online.de
Mon Oct 5 13:38:24 GMT 2026
Jon Turney wrote:
> ...
>> ...
>> There is no 'lock' prefix or 'ldadd*' in
>> winsup/cygwin/scripts/gendef. The inc/decrements of 'incyg' are
>> possibly not thread safe.
>
> I don't think thread-safety in increment/decrement is actually an
> issue because incyg is part of the TLS data which only the concerned
> thread adjusts.
Indeed, sorry for the noise.
>
> However, a memory barrier is needed here, because other threads may
> inspect incyg and make decisions about the state of the thread based
> on that (e.g. in signal delivery, and I think the assembler which
> interacts with incyg there gets that right, at least in the x86_64
> case...)
The only use case I found with a quick 'git grep -w incyg':
exceptions.cc (8f145421c9), line 1125:
tls->lock (); // InterlockedExchange(): x86_64: xchgl, aarch64: swpa
if (tls->incyg) ...
Possible fix if the lock() actually doesn't imply a barrier:
tls->lock ();
if (tls->get_incyg()) ...
inline unsigned
_cygtls::get_incyg()
{
// x86_64: lock orq $0, (%rsp); aarch64: dmb ish
__atomic_thread_fence(__ATOMIC_SEQ_CST); // or std::atomic_...
return incyg;
}
or more relaxed:
// x86_64: no code!; aarch64: dmb ishld
__atomic_thread_fence(__ATOMIC_ACQUIRE);
return incyg;
__ATOMIC_ACQUIRE/RELEASE/ACQ_REL does not emit any code for x86_64 but
for aarch64.
--
Regards,
Christian
More information about the Cygwin-developers
mailing list