Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: C++ and POS...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 9537 of 9828
Post > Topic >>

Re: C++ and POSIX threads

by Martin York <Martin.YorkAmazon@[EMAIL PROTECTED] > Apr 24, 2008 at 01:05 AM

> int main(){
>
>     pthread_t mythreads[N];    //N integer > 1
>     int ids[N];
>
>     for (int j = 0; j < N; j++)
>       ids[j] = pthread_create(&mythreads[j], NULL, /* the problem is
> here*/);

The problem is pthreads is a C library and does not know anything
about objects or methods etc. So you need to write a C bridge
function.

extern "C" void* thread_start(void* data);
void* my_thread_start(void* data)
{
     Q*  object = reinterpret_cast<Q*>(data);
     object->gg(<ARGS>);
}

int main()
{
.... stuff ...
     Q  myQ;
.... stuff ...
         ids[j] = pthread_create(&mythreads[j],
NULL,my_thread_start,&myQ);
.... stuff ...
}


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 3 Posts in Topic:
C++ and POSIX threads
mpho <tjabane@[EMAIL P  2008-04-23 14:13:19 
Re: C++ and POSIX threads
Martin York <Martin.Yo  2008-04-24 01:05:14 
Re: C++ and POSIX threads
Peter Jones <dev-null@  2008-04-24 01:43:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:36:49 CDT 2008.