- 论坛徽章:
- 0
|
这样改还是不行,运行结果还是一样
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
void *thread_1(void);
void *thread_2(void);
int main(int argc, char *argv[])
{
pthread_t pt_thread_1,pt_thread_2;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
if (pthread_create(&pt_thread_1, &attr, (void *(*)(void *))thread_1,, NULL))
{
printf("pt_thread_1 error.\n");
exit(1);
}
if (pthread_create(&pt_thread_2 &attr, (void *(*)(void *))thread_2(, NULL))
{
printf("pt_thread_2 error.\n");
exit(1);
}
pthread_join(pt_thread_1,NULL);
pthread_join(pt_thread_2,NULL);
return 0;
}
void *thread_1(void)
{
for(;;)
{
pthread_testcancel();
printf("thread_1\n");
sleep(3);
}
}
void *thread_2(void)
{
for(;;)
{
pthread_testcancel();
printf("thread_2!\n");
sleep(1);
}
}
[[i] 本帖最后由 zgx120106 于 2006-12-10 13:36 编辑 [/i]] |
|