Re: using C11's _Atomic()
[email protected] (Dave Mitchell) Wed, 6 May 2026 12:54:43 +0100
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
On Mon, May 04, 2026 at 11:39:59AM +1000, Tony Cook wrote:
[scary stuff about C++ compatibility]
Ok, my new plan for now is to add a PERL_ATOMIC() define, but not enabled
by default, nor via a configure probe. Instead it has to be explicitly
enabled via e.g. -Accflags='-DUSE_ATOMIC'. I will then use this to add
atomic to the PL_sig_* vars, which will allow me to check that
valgrind --tool=helgrind
runs cleanly. Currently it it is full of noise from the $thead->kill()
tests, thus masking whether there are any other issues.
So perl.h will have this added:
/* Not ready for production use, so currently only enabled manually
* rather than via a Configure probe.
*/
#ifdef USE_ATOMIC
# include <stdatomic.h>
/* 2 indicates guaranteed to be lock-free */
# if ATOMIC_INT_LOCK_FREE == 2 && ATOMIC_POINTER_LOCK_FREE == 2
# define PERL_ATOMIC(atype) _Atomic(atype)
# else
# define PERL_ATOMIC(atype) atype
# endif
#else
# define PERL_ATOMIC(atype) atype
#endif