I am a rookie when it comes to threads (POSIX pthreads - win32), and I am having trouble either creating a thread or declaring the functions nessesary to create that thread. I have run some thread examples that have worked, but they have always been executed in a "main()" function. My problem arises when I try to used threads in a class that has a header file. The error I get is the following:
error C2664: 'pthread_create' : cannot convert parameter 3 from 'void *(void *)' to 'void *(__cdecl *)(void *)'
I am unfamiliar with "void *" and I think that is where my problem is. Here is an example of the functions that are of importance:
Could someone please also briefly explain "void *". For example, if I wanted to pass my thread a pointer to a data object could I just replace "(void *)id" with "(DataType *)dataName" ?Code:--- example header file --- .... public: void start(void); void *function1(void*); }; --- example of source file --- ... void ClassName::start(){ pthread_t thread; int id = 0; pthread_create(&thread, NULL, function1,(void *)id); ... } void* ClassName::function1(void* id){ printf("Hey there world"); pthread_exit(NULL); }
I tried to make this question general, but if you need more detail just let me know. Thanks!



LinkBack URL
About LinkBacks


