da77ea6593d0bd401b5b00457096eb17bd448ab7
[libcds.git] / cds / os / posix / thread.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_OS_POSIX_THREAD_H
4 #define __CDS_OS_POSIX_THREAD_H
5
6 #include <pthread.h>
7
8 namespace cds { namespace OS {
9     /// posix-related wrappers
10     namespace posix {
11         /// Checks if thread \p id is alive
12         static inline bool isThreadAlive( std::thread::id id )
13         {
14             // if sig is zero, error checking is performed but no signal is actually sent.
15             // ESRCH - No thread could be found corresponding to that specified by the given thread ID
16             // Unresolved problem: Linux may crash on dead thread_id.  Workaround unknown (except signal handler...)
17             return pthread_kill( id, 0 ) != ESRCH;
18         }
19
20         /// Default back-off thread strategy (yield)
21         static inline void backoff()    
22         { 
23             std::this_thread::yield(); 
24         }
25
26     }    // namespace posix
27
28     using posix::isThreadAlive;
29     using posix::backoff;
30
31 }} // namespace cds::OS
32
33
34 #endif // #ifndef __CDS_OS_POSIX_THREAD_H