Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jan 2001 21:37:29 -0800 (PST)
From:      Joe Albowicz <joe@CS.UCLA.EDU>
To:        freebsd-hackers@freebsd.org
Subject:   need help with pthreads and memory corruption problem 
Message-ID:  <Pine.SOL.4.10.10101231304110.18109-100000@panther.cs.ucla.edu>

next in thread | raw e-mail | index | archive | help

Hello, 

I'm porting an application from Linux to FreeBSD and I am having some
problems with the program crashing in weird/random places because of
memory corruption.  For example the crash can happen in STL or free or in
c++ code that we have written (note that our code works just fine on Linux
for extended periods of time under heavy load).

The application consists of a main process plus a few dozen pthreads
written in c++. The only changes that I have made in porting from Linux to
FreeBSD consisted of Makefile changes (e.g. using -D_THREAD_SAFE) and I
replaced "new" with malloc in code that is excuted by the pthreads [except
STL may call new?].  Replacing new with malloc definately helped, but I'm
not sure why.

My questions are:

How are you supposed to build a pthreads application with c++/STL/SMP?

How are you supposed to build a linuxthreads application with
c++/STL/SMP? [Incidentally I tried this approach but still had unstable
code.  Is linuxthreads stable on FreeBSD?]

Are there reentrancy problems with STL? 

Are there (reentrancy) problems with stdlibc++/pthreads? 

What compile flags are important with c++/STL/pthreads/linuxthreads?
(what are -D_PTHREADS -D__USE_MALLOC?)


Details on the OS version, compile flags and libs are below.  Any input or
shared misery would be nice! thanks in advance!  :)

Joe


************************************************************
** uname -a

FreeBSD 4.2-RELEASE FreeBSD 4.2-RELEASE #0

** g++ --version
2.95.2

** Compile flags 

g++ -D_THREAD_SAFE -D_REENTRANT foo.cpp
[note adding -D_PTHREADS -D__USE_MALLOC seems to have stabilized it]

** Link step

g++  -v -g -pthread main.o -lxml -L./xml/lib -lz

*produces

/usr/libexec/elf/ld -m elf_i386 -dynamic-linker /usr/libexec/ld-elf.so.1
-o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L./xml/lib
-L/usr/libexec/elf -L/usr/libexec -L/usr/lib main.o -lxml -lz -lstdc++ -lm
/usr/lib/libgcc_r.a -lc_r /usr/lib/libgcc_r.a /usr/lib/crtend.o
/usr/lib/crtn.o



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SOL.4.10.10101231304110.18109-100000>