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" 还是出现这个警告,不知道在哪里修改可以去掉这个警告。
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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28