Re: gdb help: debugging a segfault in boost::shared_ptr
- From: Joe Seigh <jseigh_01@xxxxxxxxxx>
- Date: Tue, 05 Dec 2006 21:24:08 -0500
phear.dude@xxxxxxxxx wrote:
I am working on a multithreaded application that contains a database
connection pool which is using shared_ptr to pass connections around.
After recent changes I've been getting random segfaults in the
shared_ptr code handling ref counting. The gdb session below help
explain the context.
I acknowledge that this is most likely my own screwup, but since I am
unable to get much meaningful information from gdb, I'm starting to run
out of ideas.
The following is what I have discovered by research:
- shared_ptr is thread safe (from boost docs)
- sp_counted_base uses lock-free algorithms for refcounting (from
header)
The questions I currently have are:
- How can I get more details about the segfault? Ie. Which instruction
or memory address is involved?
- Why can't I access *pw?
- How can atomic_increment segfault? Is it possible that gdb's stack
trace is wrong?
An answer to any of these questions would be greatly appreciated.
In this case lock-free doesn't mean what you think it means. shared_ptr's
are only safe to copy if you own the source ptr (and the target ptr obviously).
There are experimental smart pointers that are atomically thread-safe.
shared_ptr isn't one of them as you found out. You'll need a mutex
to safely pass those shared_ptr's around.
--
Joe Seigh
When you get lemons, you make lemonade.
When you get hardware, you make software. .
- Follow-Ups:
- References:
- gdb help: debugging a segfault in boost::shared_ptr
- From: phear . dude
- gdb help: debugging a segfault in boost::shared_ptr
- Prev by Date: Re: new in gtk development
- Next by Date: Re: gdb help: debugging a segfault in boost::shared_ptr
- Previous by thread: Re: gdb help: debugging a segfault in boost::shared_ptr
- Next by thread: Re: gdb help: debugging a segfault in boost::shared_ptr
- Index(es):