url: http://www.cnblogs.com/TianFang/archive/2006/12/04/581369.html
ace提供的线程机制屏蔽了平台差异;
start///
#include "ace/Thread.h"
#include "ace/Synch.h"
#include <iostream>
using namespace std;
void* worker(void *arg)
{
for(int i=0;i<10;i++)
{
ACE_OS::sleep(1);
cout<<endl<<"hello world"<<endl;
}
return NULL;
}
int main(int argc, char *argv[])
{
ACE_thread_t threadId;
ACE_hthread_t threadHandle;
int nRet = ACE_Thread::spawn(
(ACE_THR_FUNC)worker, //线程执行函数
NULL, //执行函数参数
THR_JOINABLE | THR_NEW_LWP,
&threadId,
&threadHandle
);
if(nRet == -1)
{
return -1;
}
ACE_Thread::join(threadHandle);
//
int num = 4;
ACE_thread_t *threadID = new ACE_thread_t[num + 1];
ACE_hthread_t threadHanders = new ACE_hthread_t[num + 1];
nRet = ACE_Thread::spawn_n(threadID,
num,
(ACE_THR_FUNC)ThreadFunc,
this,
THR_JOINABLE | THR_NEW_LWP,
ACE_DEFAULT_THREAD_PRIORITY,
0, 0, threadHanders);
if(nRet == -1)
{
return -1;
}
for(int i=0; i<num; i++)
{
ACE_Thread::join(threadHanders[i]);
}
return 0;
}
//end///