Hello,
I am trying to work learn thread programming in C. I have my turbo C installed and its working fine. I tried to get the library "pthread.h" and relater STLport package by searching online and managed to get them and copied them in my include directory. But while compiling a simple program stated as follows, a number of errors occur. Am I installing the POSIX files in the wrong directory or is there some other way to work with threads in C. I have also checked the options->directories in C options but even that is set properly. Please do shed some light on how to configure my Turbo C to work with threads.
Thank you.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 5
void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0;t<NUM_THREADS;t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}