[libc-commits] [PATCH] D75818: [libc] Take 2: Add linux implementations of thrd_create and thrd_join functions.

Petr Hosek via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Mar 9 18:22:12 PDT 2020

phosek accepted this revision.
phosek added a comment.

In D75818#1911540 <https://reviews.llvm.org/D75818#1911540>, @MaskRay wrote:

> I think implementing pthread on top of C11 threads is plausible on Fuchsia because it just provides POSIX lite. However, the same idea copying over to Linux may not be practical. For one thing, the performance of `pthread_mutex_lock` matters. Implementing it on top of `mtx_lock` costs an extra function call, not to say that some features are not available in C11 mutex. `mtx_*` and `thrd_*` are usely so rarely in practice. Implementing them on top of pthread will have an infinitesimal cost.

I don't think that either of these is practical, that is neither implementing pthreads on top C11 threads nor C11 threads on top of pthreads. In the former case, pthreads provide richer more complex API that's difficult to implement solely on top of the C11 threads one. In the latter case, you're forcing all platforms, even the non-POSIX ones, to implement enough of POSIX to allow the implementation of pthreads which is unnecessarily restrictive.

The solution we've adopted in Fuchsia is to implement a set of lower-level libraries, e.g. libsync <https://fuchsia.googlesource.com/fuchsia/+/refs/heads/master/zircon/system/ulib/sync/> which provide basic primitives, and then implement `mtx_t` and `pthread_mutex_t` separately on top of these rather than layering one on top of the other or vice versa.

  rG LLVM Github Monorepo



More information about the libc-commits mailing list