一个创建线程的问题
时间:2011-04-29
来源:互联网
tmp.hpp
class CCommun
{
...
public:
bool createthread(void);
void run(void);
static void * entry(void *p);
private:
pthread_t m_threadhandle;
....
}
tmp.cpp
bool CCommun::createthread(void)
{
int i_ret;
i_ret= pthread_create(&m_threadhandle,null,entry,(void*)this);
if(i_ret!=0)
return 0;
return 1;
}
void CCommun::run(void)
{
while(!b_exit)
sleep(1000);
}
void* CCommun:: entry(void *p)
{
return ((CCommun *)p)->run();
return (void*)0;
}
谁能给我说一下,上面代码中的 (void *)this , (void*)0, 以及entry定义加static的作用
class CCommun
{
...
public:
bool createthread(void);
void run(void);
static void * entry(void *p);
private:
pthread_t m_threadhandle;
....
}
tmp.cpp
bool CCommun::createthread(void)
{
int i_ret;
i_ret= pthread_create(&m_threadhandle,null,entry,(void*)this);
if(i_ret!=0)
return 0;
return 1;
}
void CCommun::run(void)
{
while(!b_exit)
sleep(1000);
}
void* CCommun:: entry(void *p)
{
return ((CCommun *)p)->run();
return (void*)0;
}
谁能给我说一下,上面代码中的 (void *)this , (void*)0, 以及entry定义加static的作用
作者: tottili 发布时间: 2011-04-29
(void *)this , (void*)0
加强制转换是因为参数需要是void*
static表示该方法是所有对象共享的,通过类名就可以调用
加强制转换是因为参数需要是void*
static表示该方法是所有对象共享的,通过类名就可以调用
作者: thefirstz 发布时间: 2011-04-29
加static 是静态成员函数,不能访问类中的非静态成员
作者: justkk 发布时间: 2011-04-29
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28