I was writing a code to create posix threads print function is printing p,q for 4 loops but it is not printing for fifth loop but the loop is called. Can someone explain the reason.
#include<stdio. h>
#include<pthrea d.h>
#define max 5
struct data{
int a;
int b;
};
struct data s[max];
void *print(void *t)
{
int p,q;
struct data *thread;
thread=(struct data *)t;
p=thread->a;
q=thread->b;
printf("%d %d\n",p,q);
}
int main()
{
pthread_t th[max];
char m[100];
int rc,x=45,y=56,i;
for(i=0;i<max;i ++)
{
scanf("%s",m);
s[i].a=x;
s[i].b=y;
//printf("%d",s[i].a);
rc=pthread_crea te(&th[i],NULL,print,(vo id *)&s[i]);
if(rc)
printf("error:% d",rc);
}
}
#include<stdio. h>
#include<pthrea d.h>
#define max 5
struct data{
int a;
int b;
};
struct data s[max];
void *print(void *t)
{
int p,q;
struct data *thread;
thread=(struct data *)t;
p=thread->a;
q=thread->b;
printf("%d %d\n",p,q);
}
int main()
{
pthread_t th[max];
char m[100];
int rc,x=45,y=56,i;
for(i=0;i<max;i ++)
{
scanf("%s",m);
s[i].a=x;
s[i].b=y;
//printf("%d",s[i].a);
rc=pthread_crea te(&th[i],NULL,print,(vo id *)&s[i]);
if(rc)
printf("error:% d",rc);
}
}
Comment