Why is jthread not presented in libc++ (using clang 18, c++26)

129 Views Asked by At

the following code just compile with "jthread not in std". with clang 18

clang++ -std=c++26 -stdlib=libc++

and the implementation of jthread is in __thread/jthread.h, but for some reason macro out. why?

#include <thread>
using namespace std::chrono_literals;

int main() {
  std::jthread t([] { std::this_thread::sleep_for(1s); });
}
2

There are 2 best solutions below

0
heap underrun On BEST ANSWER

The libc++ documentation has a webpage about C++20 status of libc++. Quoting the relevant footnote 8:

P0660: The paper is implemented but the features are experimental and can be enabled via -fexperimental-library.

Thus, just pass that flag mentioned above when compiling with Clang 18 or newer, like this:

clang++ -std=c++26 -stdlib=libc++ -fexperimental-library
0
Ralph Zhang On

I realize that jthread is actually not fully supported yet in clang 18's libc++ ...