pthread的问题很急请帮忙

fdw 2004-11-01 10:58:03
class Thread
{
....
protected:
virtual void Execute() = 0;
private:
static void * entryPoint(void* Paramer);
....
}
//创建线程
pthread_create(&m_ThreadHandle, 0, entryPoint, this);
//entryPoint 函数
void * Thread::entryPoint(void* Paramer)
{
if ( Paramer != NULL ) {
static_cast<Thread *>(Paramer)->Execute();
}
return Paramer;
}
但static_cast<Thread *>(Paramer)->Execute();出 <段错误-核心陷阱> 错误.
我用的是solaris,cc
很急的请帮我 ,一定给分.
...全文
85 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fdw 2004-11-01
  • 打赏
  • 举报
回复
已经解决了,只要build all就可以了.
哈哈...
散分
fdw 2004-11-01
  • 打赏
  • 举报
回复
我是将程序从ui-thread(solaris)和windows下以来的,所以Execute() 内部不会有问题
fdw 2004-11-01
  • 打赏
  • 举报
回复
static是pthread_create要求的
xuzheng318 2004-11-01
  • 打赏
  • 举报
回复
顶一下,继续关注!
fdw 2004-11-01
  • 打赏
  • 举报
回复
我试了都不行
wildhorseych 2004-11-01
  • 打赏
  • 举报
回复
既然entrypoint是static的就表示你希望在没有类的实例的时候也能调用它,但是为什么又要把它声明为私有的??
freefalcon 2004-11-01
  • 打赏
  • 举报
回复
看起来没有问题

你好好检查一下Paramer 参数以及Execute方法
看Execute是不是正确实现了多态
再看Execute方法内部造成的错误

像xzgyb(老达摩)那样分开写有利于界定错误
yjh1982 2004-11-01
  • 打赏
  • 举报
回复
(static_cast<Thread *>(Paramer))->Execute();
devilplus 2004-11-01
  • 打赏
  • 举报
回复
你这个this是多重继承吗,试试pthread_create(&m_ThreadHandle, 0, entryPoint, static_cast<Thread *>(this));
xzgyb 2004-11-01
  • 打赏
  • 举报
回复
应该没问题吧,
不行就直接转吧
void * Thread::entryPoint(void* Paramer)
{
Thread* pThread = (Thread *)Paramer;

if ( pThread != NULL ) {
pThread->Execute();
}
pthread_exit(NULL);
}

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧