acl/lib_acl_cpp/samples/thread/main.cpp
zsxxsz dcdebd5f9c add thread, thread_pool for lib_acl_cpp
add thread, thread_pool for lib_acl_cpp, and other bugfix
2013-10-19 23:13:19 +08:00

60 lines
1019 B
C++

#include "stdafx.h"
//////////////////////////////////////////////////////////////////////////
class mythread : public acl::thread
{
public:
mythread() {}
~mythread() {}
protected:
virtual void* run()
{
const char* myname = "run";
printf("%s: thread id: %lu, %lu\r\n",
myname, thread_id(), acl::thread::thread_self());
return NULL;
}
private:
};
//////////////////////////////////////////////////////////////////////////
static void test_thread(void)
{
const char* myname = "test_thread";
mythread thr;
thr.set_detachable(false);
if (thr.start() == false)
{
printf("start thread failed\r\n");
return;
}
printf("%s: thread id is %lu, main thread id: %lu\r\n",
myname, thr.thread_id(), acl::thread::thread_self());
if (thr.wait(NULL) == false)
printf("wait thread failed\r\n");
else
printf("wait thread ok\r\n");
}
int main(void)
{
// ³õʼ»¯ acl ¿â
acl::acl_cpp_init();
test_thread();
#ifdef WIN32
printf("enter any key to exit ...\r\n");
getchar();
#endif
return 0;
}