I have a C program with two threads one of those threads is almost all the time blocked in a fgets()
waiting for user input. The second thread may need to print to the terminal while the first one is blocked on fgets()
.
From my tests it seems that the program waits for the fgets()
on the first thread to return and then the second thread can print.
Is this who it works or could I print while the the other thread is blocked on the fgets()
?
This implementations runs on eCos (embedded Configurable operating system).
Thread locked on fgets()
:
int my_getline (char** argv, int argvsize)
{
static char line[MAX_LINE];
char *p;
int argc;
fgets(line, MAX_LINE, stdin);
for (argc=0,p=line; (*line != '\0') && (argc < argvsize); p=NULL,argc++) {
p = strtok(p, " \t\n");
argv[argc] = p;
if (p == NULL) return argc;
}
argv[argc] = p;
return argc;
}
Thread trying to print:
while(1){
unsigned char bufr[50];
read_until(bufr);
if (bufr[1] == (unsigned char)NMFL ){
cyg_mutex_lock(&scree_mtx);
printf("Memory half full!\n");
cyg_mutex_unlock(&scree_mtx);
continue;
}
cyg_mbox_put( mbx_serial_userH, bufr );
}
Output (I'm sure the message was there before):