Windows上的pthread_cleanup_pop错误 - 使其可编译

时间:2015-04-01 16:48:39

标签: c++ pthreads

代码:

    void clean(void *message)
    {
     cout<<"Exiting "<<(char*)message<<endl;
    }
    void *func2(void* arg)
    {
       char *message = "func2";
       pthread_cleanup_push(clean,(void*)message);
       int status;
       int count=0;   
       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,&status);
       for(;;){
          if(count%3467==0)
          {
              sleep(3);
              pthread_testcancel();
          }
          else if(count%67==0)
          {
              cout<<"func 2 is running"<<endl;
          }
          else
          {}
          count++;
       }
        pthread_cleanup_pop(0);//error is pointing here
    }

当我尝试编译时,我收到错误

cancel.cpp:45:5: error: second operand to the conditional operator is of type 'v
oid', but the third operand is neither a throw-expression nor of type 'void'
     pthread_cleanup_pop(cleanup_pop_arg);

我无法找到我的代码有什么问题。 使用g++ file.cpp -pthread,Windows 8,Cygwin 64编译。

如何使代码编译成功?

编辑:

预处理后,这就是它的外观。

void *func2(void* arg)
{
    char *message = "func2";
   { const _pthread_cleanup _pthread_cup = {(clean), ((void*)message), *pthread_getclean()}; __sync_synchronize(); *pthread_getclean() = (_pthread_cleanup *) &_pthread_cup; __sync_synchronize();
   int status;
   int count=0;
   pthread_setcancelstate(0x01,&status);
   for(;;){
      if(count%3467==0)
      {
          sleep(3);
          pthread_testcancel();
      }
      else if(count%67==0)
      {
          cout<<"func 2 is running"<<endl;
      }
      else
      {}
      count++;
   }
    (*pthread_getclean() = _pthread_cup.next, (cleanup_pop_arg?_pthread_cup.func((pthread_once_t *)_pthread_cup.arg):0));};

}

0 个答案:

没有答案