- 论坛徽章:
- 0
|
pthread_t _pidrunlog;
pthread_t _piddellog;
void* logsvc(void* /*pParam*/)
{
pthread_detach(pthread_self());
while(1)
{
printf("in logsvc \n" );
sleep(1);
}
}
void* logdelsvc(void* /*pParam*/)
{
pthread_detach(pthread_self());
while(1)
{
printf("in logdelsvc \n" );
sleep(2);
}
}
void Run()
{
pthread_create(&_pidrunlog, NULL, &logsvc, NULL);
pthread_create(&_piddellog, NULL, &logdelsvc, NULL);
}
void Stop()
{
printf(" cancel _pidrunlog\n" );
pthread_cancel( _pidrunlog );
printf(" cancel _piddellog\n" );
pthread_cancel( _piddellog );
}
int main()
{
Run();
sleep(10);
Stop();
return 0;
}
大家能分析下,我上面贴的代码有什么问题么?会不会有内存泄漏什么的?
我的目的很简单,调用Run()开启两线程,调用Stop()终止
[ 本帖最后由 msccao 于 2008-10-29 17:55 编辑 ] |
|