This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: bug report: std::cout and posix threads
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Re: bug report: std::cout and posix threads
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Fri, 5 Jan 2001 10:57:45 -0800
A couple of problems.
1) use -pthread on the compile line. This automatically links in the
thread library and defines macros so that thread-safe code is used.
2) make sure your compiler is configured for threads.
Using current CVS, I've been able to verify that your sample code
works. I'm unsure of your specific compiler, but I thought I'd let you
know that this should work.
Here's my compiler configuration:
Reading specs from /mnt/hd/ahimsa/bld-x86-gcc-threads/gcc/specs
Configured with: /mnt/hd/bliss/src.gcc/configure --verbose --prefix=/mnt/hd/bliss/H-x86-gcc-threads --enable-threads=posix --enable-languages=c,c++
gcc version 2.97 20010102 (experimental)
Here's the compile -v output:
/mnt/hd/ahimsa/bld-x86-gcc-threads/gcc/cc1plus -v -I/mnt/hd/ahimsa/bld-x86-gcc-threads/i686-pc-linux-gnu/libstdc++-v3/include -I/mnt/hd/bliss/src.gcc/libstdc++-v3/include/std -I/mnt/hd/bliss/src.gcc/libstdc++-v3/include/c_std -I/mnt/hd/bliss/src.gcc/libstdc++-v3/include -I/mnt/hd/bliss/src.gcc/libstdc++-v3/libsupc++ -I/mnt/hd/bliss/src.gcc/libstdc++-v3/libio -I/mnt/hd/bliss/src.gcc/libstdc++-v3/testsuite -iprefix /mnt/hd/ahimsa/bld-x86-gcc-threads/gcc/../lib/gcc-lib/i686-pc-linux-gnu/2.97/ -isystem /mnt/hd/ahimsa/bld-x86-gcc-threads/gcc/include -D__GNUC__=2 -D__GNUC_MINOR__=97 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__STDC_HOSTED__=1 -ggdb3 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ -D_REENTRANT test01.cc -D__GNUG__=2 -D__GXX_ABI_VERSION=100 -quiet -dumpbase test01.cc -ggdb3 -O0 -version -fnew-abi -o /tmp/ccLBl0ld.s
GNU CPP version 2.97 20010102 (experimental) (cpplib) (i386 Linux/ELF)
GNU C++ version 2.97 20010102 (experimental) (i686-pc-linux-gnu) compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.0).
ignoring nonexistent directory "/mnt/hd/ahimsa/bld-x86-gcc-threads/include/g++-v3"
ignoring nonexistent directory "/mnt/hd/ahimsa/bld-x86-gcc-threads/lib/gcc-lib/i686-pc-linux-gnu/2.97/include"
ignoring nonexistent directory "/mnt/hd/ahimsa/bld-x86-gcc-threads/i686-pc-linux-gnu/include"
ignoring nonexistent directory "/mnt/hd/bliss/H-x86-gcc-threads/include/g++-v3"
ignoring nonexistent directory "/mnt/hd/bliss/H-x86-gcc-threads/i686-pc-linux-gnu/include/g++-v3"
ignoring nonexistent directory "/mnt/hd/bliss/H-x86-gcc-threads/include"
ignoring nonexistent directory "/mnt/hd/bliss/H-x86-gcc-threads/lib/gcc-lib/i686-pc-linux-gnu/2.97/include"
ignoring nonexistent directory "/mnt/hd/bliss/H-x86-gcc-threads/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/mnt/hd/ahimsa/bld-x86-gcc-threads/i686-pc-linux-gnu/libstdc++-v3/include
/mnt/hd/bliss/src.gcc/libstdc++-v3/include/std
/mnt/hd/bliss/src.gcc/libstdc++-v3/include/c_std
/mnt/hd/bliss/src.gcc/libstdc++-v3/include
/mnt/hd/bliss/src.gcc/libstdc++-v3/libsupc++
/mnt/hd/bliss/src.gcc/libstdc++-v3/libio
/mnt/hd/bliss/src.gcc/libstdc++-v3/testsuite
/mnt/hd/ahimsa/bld-x86-gcc-threads/gcc/include
/usr/include
End of search list.
as -V -Qy -o /tmp/cc5a11N2.o /tmp/ccLBl0ld.s
GNU assembler version 2.10.91 (i686-pc-linux-gnu) using BFD version 2.10.91
/mnt/hd/ahimsa/bld-x86-gcc-threads/gcc/collect2 -m elf_i386 -static /usr/lib/crt1.o /usr/lib/crti.o /mnt/hd/ahimsa/bld-x86-gcc-threads/gcc/crtbegin.o -L/mnt/hd/ahimsa/bld-x86-gcc-threads/i686-pc-linux-gnu/libstdc++-v3/src/.libs -L/mnt/hd/ahimsa/bld-x86-gcc-threads/gcc /tmp/cc5a11N2.o -lstdc++ -lm -lgcc -lpthread -lc -lgcc /mnt/hd/ahimsa/bld-x86-gcc-threads/gcc/crtend.o /usr/lib/crtn.o
Here's running the executable:
%a.out
Hello from main thread
Hello from the child thread
best,
benjamin