[C++-sig] Re: shared_ptr -> weak_ptr -> shared_ptr

Christoph Ludwig cludwig at cdc.informatik.tu-darmstadt.de
Thu Apr 14 19:18:16 CEST 2005


On Thu, Apr 14, 2005 at 09:16:12AM -0700, Andreas Beyer wrote:
> My platform is
>  Python 2.4.1 (#1, Apr  8 2005, 15:53:09)
>  gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
>  boost cvs download from Apr. 5th
> 
> The program runs single-threaded. There is nothing else as what I gave 
> in my example. I didn't even use Idle for the python part, but just a 
> plain python shell.

Have you BOOST_DISABLE_THREADS defined in boost/config/user.hpp or on the
compiler's command line? 

The Boost config system cannot reliable detect under Linux whether the
compiler was called with the option -pthread. IIRC it assumes the code is MT
unless BOOST_DISABLE_THREADS was defined. So your python interpreter may be
single-threaded and you compiled and linked your test program without
-pthread, but the shared_ptr code still refers to pthread symbols unless
you defined BOOST_DISABLE_THREADS. (For some reason such mismatches are not
caught by the linker.)

I experienced the same problem some time ago and spent many hours with the
debugger before I found the problem's cause. The symptoms were similar to what
you report.

> Can someone else try to reproduce this behavior on another Linux platform?

I can't reproduce it, but then I have no single-threaded python interpreter
installed anymore. So even if the shared_ptr code refers to pthread symbols
they can be resolved when the extension module is loaded.


HTH, regards

Christoph

> Peter Dimov wrote:
> 
> >David Abrahams wrote:
> > 
> >
> >>Andreas Beyer <beyer at imb-jena.de> writes:
> >>
> >>   
> >>
> >>>Hi.
> >>>
> >>>I would like to transform a shared pointer originating from a python
> >>>object to a weak pointer. Later I would like to transform it back to
> >>>a shared pointer. For some strange reason I keep getting seg-faults
> >>>when trying to lock the weak pointer.
> >>>Is there any danger in storing shared pointers from python objects as
> >>>weak pointers?
> >>>     
> >>>
> >>Shouldn't be, especially in your case.  This behavior really surprises
> >>me.  Peter, do you have anything to say about this?
> >>   
> >>
> >
> >It should work. Is it possible that Boost.Python is single-threaded but 
> >ptr_test is mutlithreaded? Which platform? 
> >
> >
> >
> >_______________________________________________
> >C++-sig mailing list
> >C++-sig at python.org
> >http://mail.python.org/mailman/listinfo/c++-sig
> >
> > 
> >
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
> 
> 

-- 
http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html
LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html




More information about the Cplusplus-sig mailing list