Multithread error

I typed the following code into CodeLite (Linux) and it gave me the error below:

:18:62: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-fpermissive]

//CODE HERE///

#include <stdio.h>
#include <pthread.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

void *functionC();
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
int counter = 0;

main()
{
int rc1, rc2;
pthread_t thread1, thread2;

/* Create independent threads each of which will execute functionC */

if( (rc1=pthread_create( &thread1, NULL, &functionC, NULL)) )
{
printf("Thread creation failed: %d\n", rc1);
}

if( (rc2=pthread_create( &thread2, NULL, &functionC, NULL)) )
{
printf("Thread creation failed: %d\n", rc2);
}

/* Wait till threads are complete before main continues. Unless we */
/* wait we run the risk of executing an exit which will terminate */
/* the process and all threads before the threads have completed. */

pthread_join( thread1, NULL);
pthread_join( thread2, NULL);

exit(0);
}

void *functionC()
{
pthread_mutex_lock( &mutex1 );
counter++;
printf("Counter value: %d\n",counter);
pthread_mutex_unlock( &mutex1 );
}

Could anyone please explain to me why i got this error and how to correct it

Thankz for your answers and comments

The function prototype takes a void* parameter.
So how exactly should fix this problem
rmsharkey has given you an (the!) exact answer!

Your function needs to match the prototype!!
Last edited on
So how exactly should fix this problem

Your thread function should be:
1
2
3
4
void functionC(void*)
{
    //...
}


http://pubs.opengroup.org/onlinepubs/007908799/xsh/pthread_create.html
Topic archived. No new replies allowed.