|
Boost Users : |
From: Patel Priyank-PPATEL1 (priyankpatel_at_[hidden])
Date: 2006-05-11 11:04:34
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_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of JOAQUIN LOPEZ MU?Z
Sent: Wednesday, May 10, 2006 4:36 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [multi_index] Core dump in multi-index library !!
----- Mensaje original -----
De: Patel Priyank-PPATEL1 <priyankpatel_at_[hidden]>
Fecha: Miércoles, Mayo 10, 2006 10:49 pm
Asunto: Re: [Boost-users] [multi_index] Core dump in multi-index library !!
> 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_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net