我有一些静态的用户数据,如:升压lock_guard <提高::互斥>抛出异常EINVAL
private:
static std::map<unsigned long, UserDataSharedPtr> userStore_;
static boost::mutex mutexUserData;
public:
static void RemoveUserData(unsigned long id)
{
boost::lock_guard<boost::mutex> lock(mutexUserData);
std::map<unsigned long, UserDataSharedPtr>::iterator it = userStore_.find(id);
if (it != userStore_.end())
{
userStore_.erase(it);
}
}
static void AddUserData(unsigned long id, UserDataSharedPtr ud)
{
boost::lock_guard<boost::mutex> lock(mutexUserData);
userStore_.insert(std::make_pair(id, ud));
}
而在一个负载测试,我的程序崩溃在该行:
boost::lock_guard<boost::mutex> lock(mutexUserData);
随着例外:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
what(): boost::lock_error
调用堆栈:
boost::mutex::lock() at mutex.hpp:55 0x81aeb22
boost::lock_guard<boost::mutex>::lock_guard() at locks.hpp:257 0x81b2cb3
..........RemoveUserData() at ..............:69 0x81b0b28
而且boost::mutex::lock()
在mutex.hpp
pthread_mutex_t m;
void lock()
{
int const res=pthread_mutex_lock(&m);
if(res)
{
boost::throw_exception(lock_error(res));
}
}
这里pthread_mutex_lock(&m)
回报22,和我检查22 EINVAL
:The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority ceiling
我该怎么办?
我搜索了很多,但我没有运气。
谢谢。
彼得
嗯,我从EINVAL的解释:http://linux.die.net/man/3/pthread_mutex_lock –
异常只能在我进行负载测试时抛出。如果我使用Valgrind的,我怀疑这会是超级慢,Valgrind的肯定会影响程序本身。但我会尝试。 –
@Peter李:读那一页上两行。 –