Subject:
|
Re: thread class for legOS
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Mon, 21 Jan 2002 23:04:22 GMT
|
Viewed:
|
1620 times
|
| |
![Post a public reply to this message](/news/icon-reply.gif) | |
In lugnet.robotics.rcx.legos, Ross Crawford writes:
> In lugnet.robotics.rcx.legos, Eric Swalens writes:
> > > !! m_Pid = execi(&Thread::runWrapper, 0, (char**)NULL,
> > > m_Prio, m_Stack);
> >
> > IRC, every method in C++ has an implicit parameter wich is the object itself;
> > that's why you can't cast it. Try the following (does someone have a nicer
> > solution?):
> >
> > Put runWrapper() outside the class:
> >
> > int runWrapper(int, char **th) {
> > ((Thread*)th)->Run();
> > return 0;
> > }
> >
> > in Start():
> >
> > m_Pid = execi(runWrapper, 0, (char**)this, m_Prio, m_Stack);
>
> Haven't done any C++ for a while, but IIRC you just need to declare runWrapper
> as static, ie:
>
> private:
> static int runWrapper(...);
In fact, neither of these suggestions will work with the code as it stands,
because the runWrapper() function tries to call the Run() function, which is a
non-static member function. You could pass a pointer to the class instance
(this) in the argv of the execi call, ie:
m_Pid = execi(&runWrapper, 0, &((char*)this), m_Prio, m_Stack);
then in runWrapper() you do something like:
int runWrapper(int argc, char **argv)
{
Thread* pExecThread;
pExecThread = (Thread*)(*argv);
pExecThread->Run();
return 0;
}
The disadvantage is you can't use argc & argv for what they're designed - but
you're not currently doing that anyhow. You could fudge it, but it'd be more
work.
Dunno if this'll help you at all - as I said I'm a bit rusty.
ROSCO
|
|
Message is in Reply To:
8 Messages in This Thread: ![thread class for legOS -Michael Wisse (18-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: thread class for legOS -Eric Swalens (18-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: thread class for legOS -Ross Crawford (21-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/246.gif) ![Re: thread class for legOS -John A. Tamplin (21-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: thread class for legOS -Michael Ash (21-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: thread class for legOS -John A. Tamplin (21-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif) ![](/news/46.gif) ![Re: thread class for legOS -Michael Ash (22-Jan-02 to lugnet.robotics.rcx.legos)](/news/x.gif)
![](/news/x.gif) ![](/news/x.gif) ![](/news/68.gif) ![You are here](/news/here.gif)
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|