当前位置: 技术问答>linux和unix
线程编译通不过
来源: 互联网 发布时间:2016-08-09
本文导语: #include #include void temp( void *arg ) { printf( "I am temp function!n" ); } void *thread1(void * arg ) { pthread_cleanup_push( temp, 0 ); //把这句注释掉就能过了 pthread_exit((void *) 0 ); } int main() { pthread_t ptt; if( pthread_create...
#include
#include
void temp( void *arg )
{
printf( "I am temp function!n" );
}
void *thread1(void * arg )
{
pthread_cleanup_push( temp, 0 ); //把这句注释掉就能过了
pthread_exit((void *) 0 );
}
int main()
{
pthread_t ptt;
if( pthread_create( &ptt, NULL, thread1, NULL ) != 0 )
perror( "pthreadCreate error!n" );
if( pthread_join( ptt, 0 ) != 0 )
perror( "pthread_join error!n" );
return( 0 );
}
错误:
在函数thread1中:
'while' before 'int',
请教为什么会这样子阿,我句子中即没'while'也没'int',为何给我这样的错误提示?
|
pthread_cleanup_push可以实现为宏,它的定义中包含字符{,在这种情况下对应的匹配字符}就要在pthread_cleanup_pop定义中出现。
也就是说pthread_cleanup_push,要成对出现。
也就是说pthread_cleanup_push,要成对出现。
|
pthread_cleanup_push是一个宏。
$ gcc -E test.c | tail -n 30
......
void *thread1(void * arg )
{
do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (temp); void *__cancel_arg = (0); int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect (not_first_call, 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
pthread_exit((void *) 0 );
}
$ gcc -E test.c | tail -n 30
......
void *thread1(void * arg )
{
do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (temp); void *__cancel_arg = (0); int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect (not_first_call, 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
pthread_exit((void *) 0 );
}
|
关于pthread_cleanup_push的定义, 楼主可以自己看看/usr/include/pthread.h