c multithreading

Posted by coubeatczech on Stack Overflow See other posts from Stack Overflow or by coubeatczech
Published on 2010-04-24T12:34:25Z Indexed on 2010/04/24 12:43 UTC
Read the original article Hit count: 315

Filed under:
|
|

hi, there's a weird behaviour in my threads:


void * foo(void * nic){
    printf("foo");
}
void * threadF(void * ukazatel){
    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?

© Stack Overflow or respective owner

Related posts about c

    Related posts about pthread