Scanf in one thread blocks other threads in c

Viewed 37

I was writing a code for reading in one thread and printing(this part doesn't have anything to do with the reading part) in another thread. But it the scanf is blocking the other thread. The code is as follows

#include<stdio.h>
#include <pthread.h>

void prnt()
{
printf("HELLO WORLD");
}

void getinp()
{
char a[10];
gets(a);
printf("The string is %s \n",a);
}

void main()
{
    pthread_t tid1,tid;

    sleep(1);
    pthread_create(&tid1, NULL, prnt, (void *)&tid1);
    pthread_create(&tid, NULL, getinp, (void *)&tid);

    pthread_join(tid, NULL);
    pthread_join(tid1, NULL);
}
0 Answers
Related