3 #ifndef __CDS_OS_POSIX_THREAD_H
4 #define __CDS_OS_POSIX_THREAD_H
8 namespace cds { namespace OS {
9 /// posix-related wrappers
12 /// Posix thread id type
13 typedef std::thread::native_thread_handle ThreadId;
15 /// Get current thread id
16 static inline ThreadId getCurrentThreadId() { return pthread_self(); }
18 /// Checks if thread \p id is alive
19 static inline bool isThreadAlive( ThreadId id )
21 // if sig is zero, error checking is performed but no signal is actually sent.
22 // ESRCH - No thread could be found corresponding to that specified by the given thread ID
23 // Unresolved problem: Linux may crash on dead thread_id. Workaround unknown (except signal handler...)
24 return pthread_kill( id, 0 ) != ESRCH;
27 /// Default back-off thread strategy (yield)
28 static inline void backoff()
30 std::this_thread::yield();
35 using posix::ThreadId;
36 constexpr const ThreadId c_NullThreadId = 0;
38 using posix::getCurrentThreadId;
39 using posix::isThreadAlive;
42 }} // namespace cds::OS
45 #endif // #ifndef __CDS_OS_POSIX_THREAD_H