I am trying to create a function that returns an object with certain type. The problem is that create thread does not accept it. Can somebody help me with the following code?
struct thread_args
{
Key *k;
QNode *q;
uint8_t USED_DIMENSION;
};
QLeafNode *st ;
struct thread_args Structthread2;
Structthread1.k=min;
Structthread1.q=start;
Structthread1.USED_DIMENSION=4 ;
pthread_create( &thread1, NULL,(void*)&FindLeafNode, ((void *) &Structthread1));
pthread_join( thread1, (void**)st);
QLeafNode* FindLeafNode (Key *k, QNode * r, uint8_t USED_DIMENSION ){
}
First off, your thread function is not correctly defined. Only functions of the form:
can be passed to
pthread_create.Now, in order to return a pointer to something from this function, you need two pthread functions:
Call this inside the thread function to return a value through
value_ptrandCall this inside the parent thread to wait for the termination of the child with handle
threadand retrieve the value returned bypthread_exitinvalue_ptr.So your code should look something like: