Re: Basic Question on POSIX Threads
On Oct 14, 8:52 pm, JackC <jeche...@gmail.com> wrote:
I am trying to get posix threads working from within an object, heres
some code:
int NConnection::TheadControl()
{
int thread_id;
pthread_t new_connection;
pthread_create(&new_connection, NULL, PriC, (void *)thread_id);
return 0;
}
void *NConnection::PriC(void *threadid)
{
}
However it that pthread_create() doesnt match void* (*)(void*)
Any ideas on how i can correct this?
By giving pthread_create the type of function that it requires:
an `extern "C" void* (*)( void* )'. Member functions, even
static member functions, cannot be extern "C", so can't be used.
Also assuming that is fixable from within a class, is it possible
once thread is running to send custom signals to it? i.e if i have 4
threads open, is there anyway to send data to the thread function once
its running if that makes any sense?
It doesn't, really. The classical way of sending data to
another thread is to use some sort of message queue, but of
course, there's nothing standard. (On the other hand, it's
pretty easy to implement using conditions and std::deque.)
--
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