According to configure.ac, stdatomic.h is optional, with a notice being emitted if it is absent. (Side note: The message says “Your compiler or platform does have a working C11 stdatomic.h” which may be incorrect wording?) PEP 7 also states that C11 is required, without any optional features (stdatomic being an optional feature). However, a user attempting to compile on a non-standard platform is running into a problem with compiling, after having a successful configure (with the notice about there being no stdatomic).
Currently, pyatomic.h is included unconditionally in Python.h, and pyatomic.h will load up one of the subheaders pyatomic_{gcc,std,msc}.h or error out. This suggests that some form of atomic support is mandatory, which isn’t mentioned in PEP 7.
Are there any supported platforms that do not have stdatomic.h?
Thanks! My reading of that thread is that it’s probably going to be mandatory? I think? If that’s the case, then PEP 7 should be updated and the configure script changed to make that a hard requirement.
Currently, the GCC implementation is used even if the C compiler is GCC, even if C11 atomics are supported. It seems like Include/cpython/pyatomic.h works on all platforms supported by PEP 11.
Maybe some platforms are missing <stdatomic.h> but use GCC. I don’t know.
CPython has required atomic support to build for a while now. It doesn’t require stdatomic support, and as explained elsewhere will fall back to platform-specific code, but will error out if it can’t find a platform-specific definition at build time.
I suspect the person in the other thread is using a somewhat nonstandard compiler setup that isn’t covered by CPython’s CI, and is somehow not hitting the LLVM or GCC-specific fallbacks in the pyatomic header. Some more info about what compiler toolchain they’re using would be helpful, I think, unless I missed that detail somewhere.
but “C11 standard” doesn’t mandate stdatomic, so it’s entirely possible that it’s not GCC and doesn’t have stdatomic.
I’ll ask, as I’m not sure the OP of that thread saw this thread.
That sounds like the wording of the configure message should be adjusted, then; the build requires stdatomic now, as opposed to potentially requiring it in the future.
I don’t think that’s quite right either. It sounds like it requires some implementation of atomics now. But that can be GCCs or MSVCs pre-standard implementation and not the C standard library one.
You need an implementation of pyatomic.h. Currently, that’s either stdatomic.h, __builtin_atomic, or Windows intrinsics. Most non-Windows compilers support some GCC extensions. You should check if the compiler supports GCC-style __builtin_atomicand, if so, adjust the conditional guards. Otherwise, you need to provide your own compatible pyatomic.h
For Python 3.11 and newer versions, use C11 without optional features. It’s OK to use optional features for which we have CPython-specific wrappers (notably, atomics).
The public C API should be compatible with C99 and C++. We also have CPython-specific wrappers for several newer features; it’s OK to use those.
IMO, info on how to add new features is out of scope for a style guide.
There might be some value in being able to build a thread-less version of Python without atomics. That’d be better than broken thread-unsafe version, and would make it easy to get a minimal level of support on esoteric platforms.
It probably isn’t as simple to do that as I’m imagining though. And may not reach the “worth the effort” barrier.
There are plenty of applications where embedding a simpler CPython without threads would be beneficial. Anywhere that you have your own threading already and want to evaluate some Python code within it would make perfect sense. It’d probably take careful locking/scheduling on the part of the embedder, but if you’re doing anything halfway interesting (e.g. rendering video/3D) then you’ll already have it.
So I’d certainly be in favour of a build option to omit everything that assumes CPython is responsible for all its own synchronisation.
Sounds you’d want to replace, rather than omit, the threading parts? pythreading.h does that for atomics; thread_*.h do that for threading itself. (I wouldn’t be surprised if this bit-rotted, but we can’t really prevent that without tests and active & involved users.)
As for platforms that are actually thread-less – we’ve left those to MicroPython, and CPython is better for it. A library can spin up a thread whenever it likes.