Re: [Boost-users] [multi_index] Core dump in multi-index library !!

Hi Joaquin,
I have put some locks in code and follows is the changed code. Also, I have removed API that takes procedure pointer. Instead it just takes id as input. Anyways, It seems to be working GREAT.
Thanks for all your help. Will contact you incase of any problems.
#include "../include/Procedure_Pool.h"
int Procedure_Pool::add_by_id(Procedure * _procedure)
{
LD_TRACE("Procedure_Pool::add_by_id");
ACE_ASSERT(_procedure != 0);
ACE_DEBUG((LM_DEBUG, "ADDING %d\n", _procedure->id()));
if (find_by_id(_procedure->id()) == 0) {
// procedure not found
mutex_.acquire();
procedure_by_id_.insert(_procedure);
mutex_.release();
// debug info
ACE_DEBUG((LM_DEBUG, "Added procedure : %d \n", _procedure->id()));
// return success
return 0;
} else {
// error
ACE_ERROR((LD_ERROR "%N:%l Error in adding procedure : %d \n", _procedure->id()));
// return failure
return -1;
}
}
int Procedure_Pool::remove_by_id(Procedure * _procedure)
{
LD_TRACE("Procedure_Pool::remove_by_id");
ACE_ASSERT(_procedure != 0);
ACE_DEBUG((LM_DEBUG, "REMOVING: %d \n", _procedure->id()));
if (find_by_id(_procedure->id()) != 0) {
// procedure found
mutex_.acquire();
procedure_by_id_.erase(_procedure->id());
mutex_.release();
ACE_DEBUG((LM_DEBUG, "Removed procedure : %d \n", _procedure->id()));
return 0;
} else {
ACE_ERROR((LD_ERROR "%N:%l Error in removing procedure : %d \n", _procedure->id()));
return -1;
}
}
Procedure * Procedure_Pool::find_by_id(int _id)
{
LD_TRACE("Procedure_Pool::find_by_id");
mutex_.acquire();
Procedure_By_Id::iterator it = procedure_by_id_.find(_id);
if (it != procedure_by_id_.end()) {
ACE_DEBUG((LM_DEBUG, "%N:%l Found procedure for id: %d \n", _id));
mutex_.release();
return *it;
}
ACE_DEBUG((LM_DEBUG, "%N:%l Not able to found procedure for id: %d \n", _id));
mutex_.release();
// return null
return 0;
}
Thanks,
Priyank
-----Original Message-----
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of JOAQUIN LOPEZ MU?Z
Sent: Wednesday, May 10, 2006 4:36 PM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [multi_index] Core dump in multi-index library !!
----- Mensaje original -----
De: Patel Priyank-PPATEL1
Hi Joaquin, [...] One other thing, addition and deletionIs done by separate threads in my application.
Oh, oh. multi_index_container is *not* thread safe, so this smells like the problem --and it is not, it certainly has the potential to crash your app sooner or later. Please take into account thread unsafety extends to every member function of multi_index_container, so you'd better lockguard *every* public method of Procedure_Pool. Looking fwd to knowing your results. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo In case you're wondering, STL implementations typically have the same level of thread safety as B.MI provides: 1. Concurrent access to different containers is safe. 2. Concurrent read-only access to the same container is safe. The rationale is that locking every public method of an STL container adds an unavoidable runtime overhead (you might not need it), and moreover it doesn't necessarily map to what constitutes *atomicity* to a given app --in your case, for instance, atomicity, and thus lockguarding, is best done at the level of Procedue_Pool interface. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Procedure * Procedure_Pool::find_by_id(int _id) { LD_TRACE("Procedure_Pool::find_by_id"); mutex_.acquire(); Procedure_By_Id::iterator it = procedure_by_id_.find(_id); if (it != procedure_by_id_.end()) { ACE_DEBUG((LM_DEBUG, "%N:%l Found procedure for id: %d \n", _id)); mutex_.release(); return *it; } ACE_DEBUG((LM_DEBUG, "%N:%l Not able to found procedure for id: %d \n", _id)); mutex_.release(); // return null return 0; }
BTW, As a side note, I highly recommend you to use ACE Guards (RAII...) for the mutex thing. Kobi

Patel Priyank-PPATEL1 ha escrito:
Hi Joaquin,
I have put some locks in code and follows is the changed code. Also, I have removed API that takes procedure pointer. Instead it just takes id as input. Anyways, It seems to be working GREAT. Thanks for all your help. Will contact you incase of any problems.
Hello Priyank, I'm glad the issue has been sorted out at last. Good luck with your project, and thank you for using Boost.MultiIndex. I second Kobi Cohen-Arazi's advice of using RAII-based ACE guards for the mutex locking/unlocking. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (3)
-
Joaquín Mª López Muñoz
-
Kobi Cohen-Arazi
-
Patel Priyank-PPATEL1