diff --git a/libcxx/include/thread b/libcxx/include/thread --- a/libcxx/include/thread +++ b/libcxx/include/thread @@ -229,7 +229,8 @@ template ::type, thread>::value + !is_same::type, thread>::value && + !is_same::type, native_handle_type>::value >::type > _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS @@ -239,6 +240,12 @@ _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS explicit thread(_Fp __f); #endif + + _LIBCPP_INLINE_VISIBILITY + explicit thread(native_handle_type __handle) + : __t_(__handle) + { } + ~thread(); _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.constr/ctor.native_handle.pass.cpp b/libcxx/test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.constr/ctor.native_handle.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.constr/ctor.native_handle.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-has-no-threads + +// + +// This test tests the constructor from a native handle provided as an +// extension to std::thread. + +// class thread + +// thread::thread(native_handle_type); + +#include +#include +#include + +#include "test_macros.h" + +bool ran = false; +void* f(void*) { ran = true; return NULL; } + +int main(int, char**) { + pthread_t native; + pthread_create(&native, NULL, f, NULL); + std::thread t(native); + assert(t.native_handle() == native); + t.join(); + assert(ran); + + return 0; +}