I tried to implement multithreading using codeblocks in ubuntu.
I typed the following program.
void *myThreadFun(void *vargp)
{
sleep(1);
printf("Printing hi from Thread \n");
return NULL;
}
int main()
{
pthread_t tid;
printf("Before Thread\n");
pthread_create(&tid, NULL, myThreadFun, NULL);
pthread_join(tid, NULL);
printf("After Thread\n");
exit(0);
}
But I couldn't compile and run the program in codeblocks. I got the following error
multithread.c undefined reference to 'pthread_create'
multithread.c undefined reference to 'pthread_join'
can someone help me out
I had used the following header files in the code:
pthread.h
stdio.h
stdlib.h