Hello,
Am 27.09.2012 05:38, schrieb John Tsiombikas:
> Hello everyone! It's been a long time since I was last on usenet 
>
> I was anxious to use the new standard C11 threading features, instead of
> platform-specific APIs, but unfortunately my system libc (GNU libc) does
> not implement that bit that yet.
> So, I wrote a trivial C11 thread wrapper over POSIX threads, and
> released it in the public domain just in case anyone is itching to use
> standard C threading in a new project just like me:
> https://github.com/jtsiomb/c11threads
There is a major flaw in your implementation that concerns the type of
the thread functions. You are simply casting C11 function type
int f(void*)
to the POSIX type
void* f(void*)
That is not only undefined behavior what is concerned C, but also
dangerous. The calling conventions for these type of functions may be
different on a given architecture, e.g returning the int value in a
reserved register and the void* on the stack.
Taking care of that incompatibility between C11 an POSIX threads needs
a bit more care than that, I think, if you want to be portable.
> The wrapper is so thin, I didn't think it made sense to make a proper
> library out of it, so it's just a header file with "static inline"
> functions. Drop it in your project, link with pthread and you're good to
> go.
>
> Disclaimer: I used a draft of the C11 standard while writting this code,
> since I don't actually have the final document. Feel free to notify me
> of any glaring discrepancies or omissions.
The xtime things are gone in the final version and all is now done
with the time structures as they existed before.
There is already an implementation of C11 threads as a wrapper around
POSIX threads that is publicly available. It is integrated in P99:
http://p99.gforge.inria.fr/
The C11 compatibility wrapper of P99 should be completely interface
compatible to C11 threads. (the include files are named differently,
though.)
Basically it also is a shallow wrapper using inline functions around
POSIX, but in addition P99 also offers
- an implementation/wrapper for the atomics
- of thread local variables
- _Generic (emulated through a macro)
if they are available (generally through gcc and friends)
Jens