the following is a c program where I want to implement an array of thread. there are two thread functions. I want to send an int value inside each function. But the code isn't giving any output. sample program:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
void * threadFunc1(void * arg)
{
int id = *((int *) arg);
printf("Inside threadfunc2 for thread %d",id)
}
void * threadFunc2(void * arg)
{
int i= *((int *)arg);
printf("Inside threadfunc2 for thread %d",i)
}
int main(void)
{
pthread_t thread[10];
for(int i=0;i<10;i++)
{
pthread_create(&thread[i],NULL,threadFunc1,(void*)&i ); // want to send the value of i inside each thread
pthread_create(&thread[i],NULL,threadFunc,(void*)&i );
}
while(1);
return 0;
}
Is there anything wrong in the code?
std::thread, that's one thing wrong. Then, the C tag in your question would be wrong, too. In any case, it lacks info what the code does when executed and what you expected. My crystal ball tells me that you should try to output the pointer passed to the thread function using the%pformat specifier or just streaming it tostd::cout.