Re: Creating thread in C++
On Dec 26 2007, 3:59 pm, Dave Rahardja
<drahardja.place...@sign.here.pobox.com> wrote:
On 2007-12-26 08:11:12 -0600, mthread <rjk...@gmail.com> said:
I get compilation error when i do this. I have a good
experience in multithreaded programming using C. But this is
the first time I am trying to do it in C++. I might be
naive. I would like to know how I can create a thread in
C++ (using C posix threads).
C++ doesn't have any concept of threads.
Bullshit. The C++ standard doesn't mention the word in its last
approved edition (althoug it does in the current draft). But
C++ is more than just the standard---things like usability and
portability are also considerations.
And of course, in this case, the fact that threads are involved
is irrelevant to his problem.
Try asking in a group for your platform instead.
No. It's very definitely a C++ problem, and not a Posix
problem. The answer would be the same under Windows, but of
course, different if he were using C.
ps: hint: you need a static member function.
PS: that's not sufficient. The type of function expected by
pthread_create is a ``extern "C" void* f( void* )'', and a
member function, static or not, can never have this type. He
needs a free function (or a broken compiler---g++ will accept a
static member, even in strictest compatibility).
And for the record, from what I've read in the Windows
documentation, you need a function declared with a language
extension (in this particular case, at least)---the Windows
documentation says that the function must be declared WINAPI.
(I don't know, off hand, whether a static member can be WINAPI
or not. Once we enter the realm of compiler extensions,
anything goes, and you'll have to read the documentation.
Provided you can find it.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34