i was trying to write a simple multithreaded program. It is dumping the core. I have my function that is called when a thread is created below:
void *BusyWork(void *t)
{
int i;
int *tid;
int result=0;
tid = t;
printf("Thread %d starting...
",*tid);
for (i=0; i<10; i++)
{
result = result + (i* i);
}
printf("thread %d is sleeping for %d sec s
",tid,tid);
sleep(tid);
printf("Thread %d done. Result = %e
",tid, result);
pthread_exit((void*) t);
}
My call to pthread_create function is below inside the main function:
int t;
for(t=0; t<NUM_THREADS; t++)
{
printf("Main: creating thread %d
", t);
rc = pthread_create(&thread[t], &attr, BusyWork, (void *)t);
}
Please help me in finding where is the problem? Thanks in advance.