免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1110 | 回复: 0
打印 上一主题 下一主题

[VMware] 通知--win2000 + vmware + redhat9 下线程库函数的一个BUG [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-07-21 11:02 |只看该作者 |倒序浏览
今天发现win2000 + vmware + redhat9下,
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,&nOldType);
没有起作用,也就是说就算设置了PTHREAD_CANCEL_DISABLE,也会被pthread_cancel 函数cancel掉
测试程序如下

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <pthread.h>

  6. pthread_t pid1;
  7. void func_1(void)
  8. {
  9.         int i ;
  10.         int nOldType;
  11.         int nRet = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,&nOldType);
  12.         printf("nRet = %d\n",nRet);
  13.         if ( nOldType == PTHREAD_CANCEL_ENABLE)
  14.                 printf("old type is enable\n");
  15.         nRet = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,&nOldType);
  16.         if ( nOldType == PTHREAD_CANCEL_DISABLE)
  17.                 printf("old type is disable\n");
  18.         for(i = 1 ;i<60;i++)
  19.         {
  20.                 printf("%d\n",i);
  21.                 sleep(1);
  22.         }
  23.         pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
  24.         for(i = 1 ;i < 10; i++ )
  25.         {
  26.                 printf("test %d\n",i);
  27.                 sleep(1);
  28.         }

  29.         return ;
  30. }
  31. void * thread_func_1(void * arg)
  32. {
  33.         func_1();
  34.         return NULL;
  35. }

  36. int main(int argc,char ** argv)
  37. {

  38.         pthread_create(&pid1,NULL,thread_func_1,NULL);
  39.         sleep(10);
  40.         pthread_cancel(pid1);
  41.         printf("cancel thread1\n");
  42.         pthread_join(pid1,NULL);
  43.         return 0;
  44. }
复制代码

在IBM的AIX下,        
for(i = 1 ;i<60;i++)
{
        printf("%d\n",i);
        sleep(1);
}
会被全部执行完,也就是说执行printf("%d\n",i)60次
而在win2000 + vmware + redhat9 下 只会执行10次printf,也就是10次后受到cancel信息,但是之前设置的
int nRet = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,&nOldType);
没有起作用。

有兴趣的朋友们在自己环境下编译测试下看看,然后把结果告诉大家。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP