Geoff Clare <g...@opengroup.org> wrote, on 17 Apr 2019: > > ... does anyone know of an implementation > that has pthreads and C11/C17 threads, with pthread_t and thrd_t defined > as different types?
My thanks to the people who replied. So it seems there are several implementations now that all have pthread_t and thrd_t as the same type, and nobody has (yet) identified one that doesn't. This is good (in a way) but leads to some complications as to how the standard should specify the relationship between thread IDs with different origins. If they are required to be the same type, the question arises as to whether they should be completely interchangeable. The answer to that is no, because the thread exit status is different (for pthreads it is void *; for C11/C17 threads it is int). This means we will have to say that the behaviour is undefined if pthread_join() is called for a thread created using thrd_create() or thrd_join() is called for a thread created using pthread_create() or via a SIGEV_THREAD notification, and is undefined if pthread_exit() is called in a thread created using thrd_create() or thrd_exit() is called in a thread created using pthread_create() or via a SIGEV_THREAD notification. But it gets worse: what about the initial thread? POSIX and C17 allow pthread_exit() and thrd_exit(), respectively, to be called from the initial thread, and it looks like there is nothing in C17 to forbid calling thrd_join() on the initial thread (it says "The thread identified by thr shall not have been previously detached or joined with another thread" and this condition is true for the initial thread), although it's not clear to me whether in POSIX the initial thread is required to be joinable. Anyway, thrd_join() alone is enough of a problem: are we really going to have to say that if thrd_join() is called on the initial thread and that thread terminates (or has terminated) by calling pthread_exit(), the behaviour is undefined? Another complication is cancellation. If pthread_cancel() is called for a thread that was created using thrd_create(), then that's a problem because thrd_join() has no way to indicate that the thread was cancelled. We can't reserve an exit status value for it, because conforming C17 programs are entitled to use the full [INT_MIN,INT_MAX] range of exit status values. I would be nervous about adding a thrd_canceled enumerator because that might be seen as trespassing on an area that "belongs" to the C committee. (I suppose we could seek their blessing for the addition.) We may have to resort to another statement about undefined behaviour. Any suggestions? -- Geoff Clare <g.cl...@opengroup.org> The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England