As my next spare-time project, I’m considering writing a suite of compatibility header and associated library, that eases the transition from Single Unix Specification v4 to v5 and C11/C17 to C2X. C++ will not be my concern, but it adds to the discussion.
As we know, when a POSIX thread exits, it returns a pointer to a thread that joins with it, where as C11 thread returns an int
. This is the issue that’s stalled my thinking. I thought of the following option:
-
Make users use POSIX thread regardless of platform and version of standard conformance, as Pthread had existed longer, and has wider support even on non-POSIX platforms. This solution is the one I prefer the most so far, but I worry the extra feature of POSIX real-time facilities on the function prototypes may hamper the portability of my compatibility layer (because C11 threads don’t have them).
-
Contract to
int
, since on ILP32 platforms, it’s same as pointers. On systems that runs executables of foreign architecture (e.g. throughqemu-user
), pointer may be 32-bit anyway, so when 2 processes of different pointer width share memory (e.g. throughmmap
), some conflict has to occur. -
Similar to 2, but ignore thread exit value anyway, as C++ does this.
What can I do to maximize portability and adoptability of my potential library with regard to difference in thread exit value type?