Question about locking in IO function

Martin Peterlin martin@luxonis.com
Mon Jul 19 14:38:57 GMT 2021


Hi.

I stumbled upon an issue on an embedded platform, where a thread was
waiting for characters using fgetc(stdin) and another thread couldn't
complete a fileno(stdin) call.

The following snippet reproduces it:

std::thread t1([](){
    fgetc(stdin);
});
std::this_thread::sleep_for(std::chrono::seconds(1));
printf("fileno(stdin): %d\n", fileno(stdin));
t1.join();

I ran this on both embedded platform and host, and host successfully
executed fileno, while embedded platform got stuck on fileno, waiting for a
mutex which was taken by fgetc.

The embedded platform is supposedly running newlib-3.3.0 and host is Ubuntu
20.04 (glibc 2.31).

Is this expected behavior? Is there a configuration option for some kind of
multithreaded IO?
I'm new to newlib and am not aware of all its possibilities and options.

Best regards,
Martin Peterlin


More information about the Newlib mailing list