There's a weird behavior in my threads:
void * foo(void * nic){
printf("foo");
}
void * threadF(void * pointer){
printf("1\n");
pthread_t threadT;
pthread_attr_t attr;
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_create(&threadT,NULL,&foo,(void*)NULL);
printf("2\n");
while (!feof(stdin)){
int id, in, out;
fscanf(stdin,"%d:%d:%d",&id,&in,&out);
}
}
int main(){
pthread_attr_t attr;
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_t threadT;
pthread_create(&vlaknoVstupu,&attr,&threadF,(void*)&data);
pthread_join(threadT,NULL);
pthread_attr_destroy (&attr);
}
// I skipped irelevant parts of code...
the thing is that sometimes the output is 12foo
, but usually just 12
.
Then the function waits for input. I would expect it to be always 12foo
. Do anybody know why are my expectations wrong?
Edit: when I type some input like 1:1:1
, which results in going through the while cycle again, there is always the foo
output.