54 thread() : hThread(INVALID_HANDLE_VALUE), dwThreadId(0) {}
58 if(hThread != INVALID_HANDLE_VALUE)
59 ::CloseHandle(hThread);
70 hThread = ::CreateThread(NULL,
76 return hThread != INVALID_HANDLE_VALUE;
82 inline bool get_exit_code(LPDWORD lpdwExitCode)
84 return ::GetExitCodeThread(hThread, lpdwExitCode)!=0;
89 inline bool is_terminated()
const
91 if(hThread==INVALID_HANDLE_VALUE)
return true;
92 return ::WaitForSingleObject(hThread, 0) == WAIT_OBJECT_0 ;
97 inline bool is_running()
const
99 if(hThread==INVALID_HANDLE_VALUE)
return false;
100 return ::WaitForSingleObject(hThread, 0) != WAIT_OBJECT_0 ;
107 return ::TerminateThread(hThread, 0)!=0;
111 bool join(
unsigned int timeout = INFINITE)
113 return ::WaitForSingleObject(hThread, timeout) == WAIT_OBJECT_0 ;
116 static int hardware_concurrency()
118 SYSTEM_INFO info={{0}};
119 ::GetSystemInfo(&info);
120 return info.dwNumberOfProcessors;
138 class runnable:
public thread {
141 static DWORD __stdcall CALLBACK _thread_proc(
void *p)
143 return (DWORD) (
reinterpret_cast<runnable*
>(p))->the_thread();
149 virtual void * the_thread() = 0;
151 virtual ~runnable() { }
189 int ret = pthread_create(&m_thread, 0,
205 return pthread_join(m_thread, 0);
208 static int hardware_concurrency()
210 int const count=sysconf(_SC_NPROCESSORS_ONLN);
211 return (count>0)?count:0;
217 static void * _thread_proc(
void *p)
219 return (
void *) (
reinterpret_cast<runnable*
>(p))->the_thread();
223 virtual void * the_thread() = 0;
pthread thread creation params
Definition: function.h:95
bool join() const
wait for thread terminataion
Definition: thread.h:203
bool kill() const
force termination of thread
Definition: thread.h:196
bool create_thread(const sprint::thread_function &p)
run per C thread using a sprint::thread::function
Definition: thread.h:187
thread()
Ctor.
Definition: thread.h:180
void run()
run the thread method
Definition: thread.h:228