reentrancy and cout/stdout
Joel Sherrill
joel@OARcorp.com
Wed Jun 20 15:31:00 GMT 2001
Hi,
I am tracking down a problem in a multi-threaded run-time in which it
appears that
the FILE * associated with cout is cached internally to libio. This is
with the
libio shipped with gcc 2.95.2. I do not have a working gcc 3.0 to
compare behaviors.
RTEMS uses the newlib reentrancy structure on a per-thread basis.
Each thread gets its own stdin, out, and err structures. The symptom is
that "task2" is using the correct reentrancy structure but tries to fwrite()
using the FILE * associated "task1". Since the reentrancy structure and
FILE *
belong to different tasks, there is an accounting conflict.
I think the underlying cause is that somewhere in the bowels, libio is
grabbing a FILE * pointer and using its own local copy rather than
repeatedly using "stdout". In this system, stdout is a macro defined as:
stdio.h:#define stdout (_impure_ptr->_stdout)
So if libio assigns that to an internal variable, then that stdout ends up
being used by all tasks.
Does this description make sense? Is this the behavior in v3? Is there
a way to fix this on either side?
Thanks.
--joel sherrill
More information about the Libstdc++
mailing list