Re: (OT) passing parameters to thread functions
On Dec 29, 6:59 am, "Christopher Pisz" <some...@somewhere.net> wrote:
"teju" <rao.tejasw...@gmail.com> wrote in message
news:cbb766f6-7f72-4138-8b69-c4097267ea1d@s19g2000prg.googlegroups.com...
i am doing multithreading program in VC++...can anyone
please tell me how to pass parameters to thread functions...
i mean i have used CreateThread(null,
0,LPTHREAD_START_ROUTINE(function1),NULL,0,&dwthreadId);
now i have to pass parameter to function1();
Multithreading is not part of standard C++ and is off topic in
this newsgroup.
Not really. Multithreading isn't addressed by the standard yet,
but it will be real soon now, and there are certainly platform
independant, C++ questions which are related to multithreading.
Including this one, in fact---although teju formulated it in
terms of a Windows function, pthread_create, under Posix works
pretty much the same way.
Your best bet is to ask on one of the miscrosoft.public groups.
Which is likely to result in a wrong answer, which depends on a
bug in VC++ in order to work:-).
If that fails, then examine the LPVOID lparam argument of
CreateThread more closely. MSDN gives very good examples of
how to do exactly what you are asking. It took me 3 seconds to
google "createthread" and find the answer.
A better solution would be to use a third party portable
threading library. Something like boost::threads, for example.
(I'm not particularly thrilled by the Boost interface to
threads, but most of the other libraries I've seen are even
worse---generally significantly worse.)
As for MSDN the examples I found there all use compiler
extensions. I'm not sure whether this is necessary, however; it
certainly isn't necessary with pthread_create, nor if you use
the boost::threads interface---although the implementation
obviously does contain more than a few platform dependencies,
that's not your problem.
--
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