+ -
当前位置:首页 → 问答吧 → Solaris上关于 pthread_create 的 extern "C" 警告 问题

Solaris上关于 pthread_create 的 extern "C" 警告 问题

时间:2010-09-16

来源:互联网

共有三个文件,Thread.cpp   Thread.h      main.cpp

Thread.h
======
#ifndef _THREAD_H_
#define _THREAD_H_
#include <pthread.h>

class CThread
{
private:
        pthread_t m_thread;  //保持线程句柄
public:
        CThread(void* (*threadFuction)(void*),void* threadArgv);
        virtual ~CThread();

        void JoinThread();
};

#endif


Thread.cpp   
================
#include "Thread.h"

CThread::CThread(void* (*threadFuction)(void*),void* threadArgv)
{
        // 初始化线程属性
        pthread_attr_t threadAttr;
        pthread_attr_init(&threadAttr);

        pthread_create(&m_thread, &threadAttr, threadFuction, threadArgv);
}

CThread::~CThread()
{
        // TODO Auto-generated destructor stub
}


void CThread::JoinThread()
{
        // join
        pthread_join(m_thread, NULL);
}
===================
main.cpp

#include   //省略

void* DoThreadOne(void*);
void* DoThreadTwo(void*);

int main(void)
{
    CThread* doOne = new CThread(DoThreadOne, NULL);  
    CThread* doTwo = new CThread(DoThreadTwo, NULL);  
   
    doOne ->JoinThread();  
    doTwo ->JoinThread();  

    delete   doOne ;
    delete   doTwo;
    return 0;
}

void* DoThreadOne(void*)
{
  
   return NULL;
}

void* DoThreadTwo(void*)
{
   
   return NULL;
}

编译:
===================
CC  -o main    main.cpp  Thread.cpp   
出现警告:
"Thread.cpp", line 9: Warning (Anachronism): Formal argument 3 of type extern "C" void*(*)(void*) in call to pthread_create(unsigned*, const _pthread_attr*, extern "C" void*(*)(void*), void*) is being passed void*(*)(void*).
1 Warning(s) detected.

怎样去掉这个警告,在网上找了相关资料,是加 extern  "C"
我试过在void* DoThreadOne(void*)和void* DoThreadTwo(void*)前面加  extern "C" 还是出现这个警告,不知道在哪里修改可以去掉这个警告。

作者: iacxin099   发布时间: 2010-09-16

好端端的pthread_t, pthread_create, pthread_join不用; 非要弄成这样……
实在让人很费解

作者: OwnWaterloo   发布时间: 2010-09-16