Boost C++ Libraries: Ticket #3272: Boost::shared_ptr crash when used in stl queue https://svn.boost.org/trac10/ticket/3272 <p> Hi, We have a scenario where we are storing instances of boost::shared_ptr in a stl queue. Then we pop the data out of Queue and do further processing. If i am correct then the pop() provided by stl queue calls the destructor of the object being popped out(which in this case would be boost::shared_ptr instance). This happens in a continuous daemon process which crashes at some random point say after 6 or 8 hrs because of boost pointer corruption. Am provding a small template below as per our implementation. </p> <p> boost::shared_ptr&lt;Sample&gt; spSample; spSample.reset(new Sample()) ; </p> <p> queue.push(spSample) ; </p> <p> <em>The below processing happens in a thread. No object is being shared between threads. Each thread has its own stl queue into which the data is pumped in by parent thread as shown above. boost::shared_ptr&lt;Sample&gt; spSample1 = q.front() ; q.pop() ; </em> Will call the destructor of the shared_ptr at q.front() </p> <p> <em>some function called which takes spSample1 as paramater func(spSample1) ; </em></p> <p> Is it safe to use boost::shared_ptr with stl queue ?? </p> <p> We are using version 1.33.1. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3272 Trac 1.4.3 Steven Watanabe Fri, 17 Jul 2009 16:43:08 GMT owner, component, severity, summary changed https://svn.boost.org/trac10/ticket/3272#comment:1 https://svn.boost.org/trac10/ticket/3272#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">René Rivera</span> to <span class="trac-author">Peter Dimov</span> </li> <li><strong>component</strong> <span class="trac-field-old">Regression Testing</span> → <span class="trac-field-new">smart_ptr</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Regression</span> → <span class="trac-field-new">Problem</span> </li> <li><strong>summary</strong> <span class="trac-field-old">Boost::sherad_ptr crash when used in stl queue</span> → <span class="trac-field-new">Boost::shared_ptr crash when used in stl queue</span> </li> </ul> <p> It should be safe to use shared_ptr with std::queue. </p> <p> I don't understand exactly what you are doing. </p> <p> Does the parent thread write to the queue while the child thread is reading from it or does the parent thread fill the queue completely before launching the child? </p> <p> I'm assuming that this problem is reproducible. If you leave the process running long enough it will eventually crash. </p> <p> Unless you can provide a reduced test case, I doubt that there is much I can do to trace the problem. </p> Ticket Peter Dimov Thu, 26 Nov 2009 20:32:04 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3272#comment:2 https://svn.boost.org/trac10/ticket/3272#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Closing - we can't do anything without a test case that reproduces the problem. </p> Ticket