multithreading in C++ using POSIX

hi,
how to implement multitheading using POSIX threads...?

pthread_create( &thread1, NULL, print_message_function, (void*) message1);

Here, thread is created only for one function. What if there are multiple functions in a single thread??

Regards,
Aditi
Here's an example using pthreads directly.
http://www.cplusplus.com/forum/unices/75447/#msg405258

Here's an example using Boost.
http://www.cplusplus.com/forum/general/27758/#msg148714
thank u for the examples... :)
But what if print_message_function() has 2-3 more functions called inside?? I mean if print_message_function() is threaded, will functions inside it be threaded????

Regards,
Aditi
But what if print_message_function() has 2-3 more functions called inside?? I mean if print_message_function() is threaded, will functions inside it be threaded????
Yes, and you need to take care of the variables that are shared amongst the threads. I. e. protect concurrent access with mutexes

By the way: each thread has an unique id and so you can find out in what thread the current function is running
You're asking for trouble if you don't use thread classes. It constrains your thinking in useful ways.

If you just think about using thread functions and trying to get them to sync with each other, you're asking for trouble.
Topic archived. No new replies allowed.