[SOLVED] Posix Threads
Posted: Wed Oct 07, 2009 11:20 pm
I'm stuck. I'm starting off with Posix threads for a school assignment, and I'm confused about what's not working right.
Basically, I'm just trying to use pthread_create, and I can't get the last argument to work right. I've seen some examples that have passed NULL, but that doesn't work for me, and other places I've seen chars or ints, and I [think] I did it exactly the same, but I keep getting errors that say something like:
|error: invalid conversion from ‘void (*)(void*)’ to ‘void* (*)(void*)’|
Here's what I have atm:
If I try using "NULL" in place of "(void*)arg", I get
|error: invalid conversion from ‘void (*)(void*)’ to ‘void* (*)(void*)’|
So I don't know what I'm doing wrong.
Basically, I'm just trying to use pthread_create, and I can't get the last argument to work right. I've seen some examples that have passed NULL, but that doesn't work for me, and other places I've seen chars or ints, and I [think] I did it exactly the same, but I keep getting errors that say something like:
|error: invalid conversion from ‘void (*)(void*)’ to ‘void* (*)(void*)’|
Here's what I have atm:
Code: Select all
#include <stdio.h>
#include <pthread.h>
void MyFunction( void *data )
{
int tehData = (int)data;
printf( "Function %i", data );
pthread_exit( NULL );
}
int main( int argc, char *args[] )
{
pthread_t thread;
int iThreadId;
int arg = 11;
iThreadId = pthread_create( &thread, NULL, MyFunction, (void*)arg );
pthread_join( thread, NULL );
printf( "Return %i", iThreadId );
return 0;
}
|error: invalid conversion from ‘void (*)(void*)’ to ‘void* (*)(void*)’|
So I don't know what I'm doing wrong.