Re: using C11's _Atomic()

[email protected] (Tony Cook) Mon, 4 May 2026 09:31:37 +1000
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
On Sun, May 03, 2026 at 05:49:40PM +0100, Dave Mitchell wrote:
> So I'm envisaging doing the following. I'll add a probe to Configure which
> tries to compile and run a small C program like:
> 
>     #include <stdatomic.h>
>     _Atomic(int) count = 0;
> 
>     int
>     main() {
>         count++;
>         count += 10;
>         return count == 11 ? 0 : 1;
>     }

Presumably you'd also want to ensure that _Atomic(int) is lock free,
either with ATOMIC_INT_LOCK_FREE or atomic_is_lock_free(), since
modifying locking atomics from a signal handler is UB.

Unfortunately sig_atomic_t is signal-safe but not thread-safe.

Tony