Re: gdb help: debugging a segfault in boost::shared_ptr



I am developing a database connectivity plugin for the Remedy Action
Request System (ARS). ARS is a platform for developing form based
applications, usually for request/ticket/case management. In order to
support integrations to multiple database systems through native ARS
forms, I need a plugin that can be configured to access multiple
configured data sources.

Due to restrictions in the ARS plugin interface and performance
requirements, I've developed a database pool for the plugin so the time
used to connect to the data sources will be greatly reduced. The pool
is very simple in its design. It holds a list of database connections
not in use, and will upon request return one of these, or if none is
available create a new one. The requester is required to give the
adapter back to the pool when done with, so the pool can insert it back
to the available list. The pool will also check if the connections are
expired before returning them, and remove them if they are.

The shared_ptrs are responsible for cleaning up the database
connection. The initial idea was that if an exception occured in a
thread holding a database connection, the shared_ptr would
automatically clean it up. This might not be possible though, since the
pool might have to keep track of the connections in order to limit the
number of open connections. Unless this can be handled on another
level.

The pointers are never passed between threads outside of the pool.
Access to the pool is synchronized in the only two methods used to
access the pool, GetAdapter() and ReleaseAdapter(). The thread safety
of the pointers should therefore not be an issue anyway. This is also
indicated by the fact that this bug also occurs when using ordinary
pointers.

Thanks for enlightening me about the details of shared_ptr and
atomic-ptr though. That will probably save my day sometime :)

On Dec 6, 5:48 pm, Joe Seigh <jseigh...@xxxxxxxxxx> wrote:
phear wrote:
Putting a lock on IDatabaseAdapter.GetAdapter() did not help. Locking
Instance::GetEntry fixed it, but this ofcourse defies the purpose of
multi-threading.

I have tried using normal pointers instead, and although a lot more
rare, it still segfaults occasionally.

I am currently following a lead from valgrind, but I'm not going to
hold my breath just yet.[...]

It's not a problem with shared_ptr or with the debugger. The "lock-free"
stuff in shared_ptr is a red herring. It's an implementation issue to make
it thread-safe and could just have easily been lock based and is lock
based on some platforms. Thread-safe means that shared_ptr handle
internally shared data safely, i.e. the reference count. It does not
mean it is atomically thread-safe like Java pointers and that you
don't need some form of external synchronization if the pointers are
shared.

If you want to see what an atomically thread-safe refcount pointer looks
like, take a look at atomic_ptr inhttp://atomic-ptr-plus.sourceforge.net/

We can't give you too much specific advice on how to solve your
problem since we know few specifics on what you are trying
to accomplish.

--
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software.

.



Relevant Pages

  • Re: determining max pool size
    ... the larger the pool size, the more requests can be server. ... 500 open connections to SQL server I awfully lot.... ... close the connection without even executing the sql statement). ...
    (microsoft.public.dotnet.framework.aspnet)
  • JNDI Connection Pool issue
    ... I have found something strange with the jdk jndi connection pool. ... If you do not iterate over all the results returned by the query, ... private static HashMap connections; ... SearchResult searchResult= ...
    (comp.lang.java.programmer)
  • Re: MaxPoolSize - Recommendations
    ... Perhaps the pool is not leaking, ... using connections efficiently. ... for average 80 concurrent users. ... Microsoft doesn't have any recommendations concerning "max pool size" ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: RSX-11M-Plus Pool questions
    ... The fact that these 4 PDP-11 systems are still running after 30 ... connections along with 1 VAX 4000 and several DECServer Terminal servers). ... I have read all the RSX documentation I can find relating to pool ... I think I have a good grasp on Secondary pool. ...
    (comp.os.vms)
  • Troubleshooting Timeout expired. All pooled connections were in use and max pool size was reached.
    ... use and max pool size was reached. ... connections were in use and max pool size was reached. ... I did not see any significant activity on the webserver. ...
    (microsoft.public.dotnet.framework.aspnet)