LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1046|回复: 2

关于pthread_join的问题

[复制链接]
发表于 2003-10-21 15:11:43 | 显示全部楼层 |阅读模式
我在使用pthread_join 的时候为什么会出现EINTR错误?

还有就是线程退出时,为什么不执行
pthread_cleanup_push(&release, NULL);

// do something;

pthread_testcancel();
pthread_cleanup_pop(1);

他们调用的release函数不会被执行这是为什么???


急急急,在线等。。。。。。
发表于 2003-10-21 21:59:33 | 显示全部楼层
#include <pthread.h>
#include <stdio.h>

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

void unlock( void * arg )
{
   pthread_mutex_unlock( &lock );
printf("unlock now\n");
}

void * function( void * arg )
{
   while( 1 )
   {
      pthread_mutex_lock( &lock );
      pthread_cleanup_push( &unlock, NULL );

      /*
       Any of the possible cancellation points could
       go here.
      */
      pthread_testcancel();

      pthread_cleanup_pop( 1 );
   }
}

main()
{
pthread_create(NULL,NULL,function,NULL);
}

测试正常
虽然后面有segment fault不过push还是起伤的
自己看看自己的代码吧
 楼主| 发表于 2003-10-22 00:17:35 | 显示全部楼层
谢谢无双版主,我的问题已经解决了

是因为我中间有个函数有问题,不过为什么会导致我说的那种现象还没有查出来,正在找ing
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表