[En-Nut-Discussion] Do Threads inherit the standard file descriptiors?

bon at elektron.ikp.physik.tu-darmstadt.de bon at elektron.ikp.physik.tu-darmstadt.de
Tue Jan 7 11:10:23 CET 2014


Hello,

in the cause of tracking down some other problem, I noticed with stdout set
in main() a printf() in the new thread doesn't print to stdout. Is this
designed behaviour?

Backtrace in main():
Breakpoint 3, _putf (_putb=0x8001235 <_write>, fd=1, fmt=0x8006a58 "Running at %ld Hz\n", ap=...)
    at /home/bon/devel/ethernut_sf/nut/crt/putf.c:265
265         rc = 0;
(gdb) bt
#0  _putf (_putb=0x8001235 <_write>, fd=1, fmt=0x8006a58 "Running at %ld Hz\n", ap=...)
                                     ^^^^^
    at /home/bon/devel/ethernut_sf/nut/crt/putf.c:265
#1  0x08000920 in vfprintf (stream=0x20001768, fmt=0x8006a58 "Running at %ld Hz\n", ap=...)
    at /home/bon/devel/ethernut_sf/nut/crt/vfprintf.c:72
#2  0x080008aa in printf (fmt=0x8006a58 "Running at %ld Hz\n")
    at /home/bon/devel/ethernut_sf/nut/crt/printf.c:71
#3  0x080003d8 in main () at motctl.c:181
(gdb) c

Backtrace in the thread:
Breakpoint 3, _putf (_putb=0x8001235 <_write>, fd=4, fmt=0x8006a18 "%3d (0x%02x) detected\n", ap=...)
    at /home/bon/devel/ethernut_sf/nut/crt/putf.c:265
265         rc = 0;
(gdb) bt
#0  _putf (_putb=0x8001235 <_write>, fd=4, fmt=0x8006a18 "%3d (0x%02x) detected\n", ap=...)
                                     ^^^^^
    at /home/bon/devel/ethernut_sf/nut/crt/putf.c:265
#1  0x08000920 in vfprintf (stream=0x20001768, fmt=0x8006a18 "%3d (0x%02x) detected\n", ap=...)
    at /home/bon/devel/ethernut_sf/nut/crt/vfprintf.c:72
#2  0x080008aa in printf (fmt=0x8006a18 "%3d (0x%02x) detected\n")
    at /home/bon/devel/ethernut_sf/nut/crt/printf.c:71
#3  0x08000180 in ScanBus (bus=0x20000304) at motctl.c:115
#4  0x080001ea in I2cInit (arg=0x0) at motctl.c:131
#5  0x080001b0 in ScanBus (bus=0x20000998) at motctl.c:120
#6  0x08000140 in ScanBus (bus=0x0) at motctl.c:109
#7  0x00000000 in ?? ()

While in main fd is 1 as expected, fd is 4 in the thread. A fprintf(stdout,
... ) in the thread also has fd set to 4.

Did I miss something in the configurator?

Bye
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------m


More information about the En-Nut-Discussion mailing list