Re: creating thread in C++
- From: Marcel Müller <news.5.maazl@xxxxxxxxxxxxxxx>
- Date: Wed, 26 Dec 2007 20:24:09 +0100
Hi,
Sergei Organov schrieb:
void myclass::mythreadstub(void* arg)
{ ((myclass*)arg)->mythread();
}
...
myclass* m = new myclass();
_beginthread(&myclass::threadstub, NULL, 0, m);
Strictly speaking, this is not guaranteed to work as the function
pointer that you pass to pthread library should be declared 'extern "C"'
in C++, and you can't declare static member this way. I.e., static
member function could be incompatible with a function that pthread
library expects.
uh, I remember there have been something like this. IBM VCC++ 3.0 for OS/2 for instance uses a different calling convention for class members which cannot be changed.
The work around is to use a friend instead of a static class member function. If the entry point is public (or with some tricks protected) a statically linked function in the implementation file where _beginthread is called is sufficient. But I am unsure if a static function declaration within an extern "C" block is guaranteed.
Marcel
.
- References:
- creating thread in C++
- From: mthread
- Re: creating thread in C++
- From: Marcel Müller
- Re: creating thread in C++
- From: Sergei Organov
- creating thread in C++
- Prev by Date: Re: creating thread in C++
- Next by Date: A quetion about deadlock, priority inversion ...
- Previous by thread: Re: creating thread in C++
- Next by thread: Re: creating thread in C++
- Index(es):
Relevant Pages
|
Loading