[libc++] Support for systems lacking pthreads?

I'm trying to cross-compile libc++ for an embedded system that lacks any kind of threading support, meaning it has no pthread libraries, headers, etc. I've got a working clang,compiler-rt, newlib, and libc++abi already built and installed.

For libc++, CMake seems to test for libpthread and (properly) not find it:

-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found

But when I try to do the actual libc++ build, various source files that use pthreads are still part of the build, which causes the build to fail. For example, condition_variable.cpp:

In file included from /data0/jsk/llvm/llvm\-svn/llvm/projects/libcxx/src/condition\_variable\.cpp:10:
In file included from /data0/jsk/llvm/llvm\-svn/llvm/projects/libcxx/include/condition\_variable:111:
/data0/jsk/llvm/llvm\-svn/llvm/projects/libcxx/include/\_\_mutex\_base:27:5: error: unknowntype name 'pthread\_mutex\_t'
pthread\_mutex\_t \_\_m\_;

Is there any workaround for this issue?

Thanks.

Jeff —

Currently there is no workaround for this; libc++ is not set up to run on a system that does not have threading support.
However, Jon Roelofs, who did the “single threaded” work on libc++abi, is planning on working on that.

— Marshall

I'm trying to cross-compile libc++ for an embedded system that lacks any kind of threading support, meaning it has no pthread libraries, headers, etc. I've got a working clang,compiler-rt, newlib, and libc++abi already built and installed.

For libc++, CMake seems to test for libpthread and (properly) not find it:

   -- Looking for pthread_create in pthread
   -- Looking for pthread_create in pthread - not found

But when I try to do the actual libc++ build, various source files that use pthreads are still part of the build, which causes the build to fail. For example, condition_variable.cpp:

     In file included from /data0/jsk/llvm/llvm-svn/llvm/projects/libcxx/src/condition_variable.cpp:10:
     In file included from /data0/jsk/llvm/llvm-svn/llvm/projects/libcxx/include/condition_variable:111:
     /data0/jsk/llvm/llvm-svn/llvm/projects/libcxx/include/__mutex_base:27:5: error: unknowntype name 'pthread_mutex_t'
     pthread_mutex_t __m_;

Is there any workaround for this issue?

Jeff —

Currently there is no workaround for this; libc++ is not set up to run on a system that does not have threading support.
However, Jon Roelofs, who did the “single threaded” work on libc++abi, is planning on working on that.

Jeff,

Here's a currently-in-progress review of the libc++ patch: ⚙ D3969 [libc++] Allow libc++ to be built on systems without POSIX threads

I haven't finished it, but it should get you most of the way there. I plan to pick this back up in the near-ish future.

Cheers,
Jon

Thanks for the info.

I've temporarily hacked around this issue by creating a set of dummy (stub) pthread data types and functions (only those that libc++ and libc++abi actually use). Once the real patch is integrated into svn, I'll of course switch to that.

-- Jeff