Question about locking in IO function

Martin Peterlin <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CAOkH8N2sboDmYQ_qJ-2HUMdkD+VFotTdhtui+jDbQ0YiUz=7KA@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.