当前位置: 技术问答>gcc链接的库,分不分单线程版本的和多线程版本的?
iis7站长之家
线程清理处理程序小问题
来源: 互联网 发布时间:2017-03-17
本文导语: /*********************************************************************************/ /* 线程清理处理程序。 */ /********************************************************************************/ #include #include #include #include void cleanup(void *arg) { printf("clearup: %s...
/*********************************************************************************/
/*
线程清理处理程序。
*/
/********************************************************************************/
#include
#include
#include
#include
void cleanup(void *arg)
{
printf("clearup: %sn", (char *)arg);
}
void * fun(void * arg)
{
printf("in pthread:n");
//去掉这三句就没错,怎么会在main()函数报错阿???
pthread_cleanup_push(cleanup, (void *)"1");
pthread_cleanup_push(cleanup, (void *)"2");
pthread_cleanup_push(cleanup, (void *)"3");
/*pthread_cleanup_pop(0);
pthread_cleanup_pop(0);
pthread_cleanup_pop(3);
pthread_cleanup_pop(3);
pthread_cleanup_pop(3);*/
pthread_exit((void *)0 );
}
int main()
{
pthread_t tid1;
int err;
if ((err = pthread_create(&tid1, NULL, fun, NULL)) != 0)
{
printf("pthread1 error!n");
}
pthread_join(tid1, (void * )(0)); //获取传递的参数并等待该子线程结束。
printf("in main pthread:n");
return 0;
}
运行结果:
[root@localhost work]# gcc 1.c -o 1 -lpthread
1.c: 在函数 ‘fun’ 中:
1.c:38: 错误:expected ‘while’ before ‘int’
1.c:53: 错误:expected declaration or statement at end of input
1.c:53: 错误:expected declaration or statement at end of input
1.c:53: 错误:expected declaration or statement at end of input
1.c:53: 错误:expected declaration or statement at end of input
1.c:53: 错误:expected declaration or statement at end of input
1.c:53: 错误:expected declaration or statement at end of input
我去掉上面的三句就不会报错啊,怎么不去掉在main函数会报错啊????
|
http://wenku.baidu.com/view/fd4a162e0066f5335a812191.html
pthread_cleanup_push必须和pthread_cleanup_pop成对出现。
pthread_cleanup_push必须和pthread_cleanup_pop成对出现。