aremmell / libsir

The Standard Incident Reporter library: A lightweight, cross-platform library for information distribution.
https://libsir.rml.dev/
MIT License
33 stars 5 forks source link

Support building with native C11 threads #131

Closed johnsonjh closed 1 year ago

johnsonjh commented 1 year ago

Support compile-time option for building using native C11 threads.

This is mostly for compatibility with projects using C11 threads where their implementation is different than POSIX threads. This should be something I can easily do with macros and without invasive changes.

Testing should be possible even on systems without C11 native threads by using c11threads (which would not need to be included with libsir or a dependency, but used only by developers to verify C11 threading functionality). FreeBSD also includes libstdthreads and threads.h implementation since FreeBSD 10, described here. Their implementation is on top of Pthreads (so not a distinct implementation) but remains useful for verification. Solaris and illumos provide similar support.

Since native C11 thread implementations are not yet very widespread outside of some embedded and specialty systems, this is not a high priority issue, and does not add any new functionality.

aremmell commented 1 year ago

You know, I tried this once. macOS doesn't even provide threads.h.

johnsonjh commented 1 year ago

Yeah - it comes on musl-libc (as used on various embedded systems), Lynx, FreeBSD, illumos, Solaris, as a package for VxWorks, etc. Microsoft is apparently committed to providing the most impactful optional features in future releases, with C11 atomics and threading support on the roadmap.. Because macOS threading is (still) built on Mach threads, I'd be surprised if Mac ever gets C11 threads.

So it's very low priority because they aren't widely supported, but still would be a nice thing to have. Pthreads are usually better - they allow a lot more control too. C11 threads will (hopefully) turn out to be more of a common baseline for portability, and if you need something extra, you'd look to see if there is Pthreads support or some native threading (Windows, Solaris, AIX, Haiku ... all have their own native threads support that isn't Pthreads or C11 threads ...)

johnsonjh commented 1 year ago

That https://github.com/jtsiomb/c11threads project implements C11-compatible threads on top of Pthreads. So there isn't any point in us using it, but it would be good for testing if you don't have C11 thread support in your OS.

johnsonjh commented 1 year ago

I'm closing this for now. Too much work for no real gain at this time - there isn't anywhere we'd run that has C11 threads that aren't secondary to or based on POSIX threads.