You have reached the world's edge, none but devils play past here
0%
C++ std::thread
Posted onEdited on Symbols count in article: 5.5kReading time ≈5 mins.
linux 2.1和linux2.6在线程实现上是不同的。在Linux2.4中,LinuxThreads是用单独的进程实现每个线程的,这使得它很难与posix线程的行为匹配。在linux2.6中,对linux内核和线程库进行了很大的修改,采用了一个称为Native POSIX线程库(NPTL)的新线程实现。它支持单个进程中有多个线程的模型,也更容易支持posix线程的语义。
#if __cpp_lib_three_way_comparison friend strong_ordering operator<=>(id __x, id __y) noexcept; #else friendbool operator<(id __x, id __y) noexcept; #endif
template<class _CharT, class _Traits> friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __out, id __id); }; // member id _M_id;
// ctor public: thread() noexcept = default;
#ifdef _GLIBCXX_HAS_GTHREADS template<typename _Callable, typename... _Args, typename = _Require<__not_same<_Callable>>> explicit thread(_Callable&& __f, _Args&&... __args) { static_assert( __is_invocable<typename decay<_Callable>::type, typename decay<_Args>::type...>::value, "std::thread arguments must be invocable after conversion to rvalues" );
#ifdef GTHR_ACTIVE_PROXY // Create a reference to pthread_create, not just the gthr weak symbol. auto __depend = reinterpret_cast<void(*)()>(&pthread_create); #else auto __depend = nullptr; #endif using _Wrapper = _Call_wrapper<_Callable, _Args...>; // Create a call wrapper with DECAY_COPY(__f) as its target object // and DECAY_COPY(__args)... as its bound argument entities. _M_start_thread(_State_ptr(new _State_impl<_Wrapper>( std::forward<_Callable>(__f), std::forward<_Args>(__args)...)), __depend); }
// dtor ~thread() { if (joinable()) std::terminate(); }
inlinebool operator==(thread::id __x, thread::id __y) noexcept { // pthread_equal is undefined if either thread ID is not valid, so we // can't safely use __gthread_equal on default-constructed values (nor // the non-zero value returned by this_thread::get_id() for // single-threaded programs using GNU libc). Assume EqualityComparable. return __x._M_thread == __y._M_thread; }
1 2 3 4 5 6 7 8 9
intpthread_equal(pthread_t t1, pthread_t t2);
/* The pthread_equal() function shall return a non-zero value if t1 and t2 are equal; otherwise, zero shall be returned. If either t1 or t2 are not valid thread IDs, the behavior is undefined. */