Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 29 Aug 2014 09:56:39 +0200
From: Jens Gustedt <>
Subject: Re: C threads, v. 6.2

Am Donnerstag, den 28.08.2014, 19:38 -0400 schrieb Rich Felker:
> Perhaps I should clarify: what I mean by "what we're doing" is
> defining pthread_mutex_t and mtx_t as separate structs with identical
> contents (a single union with no tag). Your latest version with
> __pthread_mutex_t is not a possibility because it changes the C++ ABI.
> In principle we could do something like with the definition of
> pthread_t where it changes depending on whether the header is being
> used in a C or C++ program, but that's quite ugly and not something
> I'd much like to do...
> Is your conclusion still that it's okay? I think so but I just want to
> confirm.

Ok, now I see.

(for the discussion let's just take mutexes as example, similar would
apply for cv)

Yes, done carefully this would be an option. By carefully meaning that
we have to ensure that all TU see only either type, not both.

For pthread this would be easy, basically nothing changes, good.

For C threads that base themselves on pthread this would be a pain. We
have to call pthread functions with mutex parameters. We couldn't just
simply include the pthread.h header, since this would drag in the
pthread type definitinions.

We could get away with it, by some hackery

** Option 1:

C threads do something like the following in all C thread TU, or have
an intermediate header "threads_impl.h" that does this

typedef mtx_t pthread_mutex_t
#define __DEFINED_pthread_mutex_t

#include "pthread_impl.h"

** Option 2:

In "pthread_impl.h" have:

typedef pthread_mutex_t __pthread_mutex_t;

In "threads_impl.h" have:

typedef mtx_t __pthread_mutex_t;

and then let all __pthread_xxxxx functions that we provide to be used
by the C thread implementation use __pthread_mutex_t.


All of this would explode in our face the day a user wants to use
pthread_mutex_t and mtx_t in the same application. A use case could be
that he uses one library that protects CS with pthread_mutex_t and
another that uses mtx_t. Now suddenly we have code that sees two
different types, with possibly subtle bugs due to aliasing.

So in conclusion, it is doable, but I don't like it at all.


:: INRIA Nancy Grand Est ::: AlGorille ::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: ::

Download attachment "signature.asc" of type "application/pgp-signature" (199 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.