Wednesday, 21 August 2013

std::lock_guard segfaults on construction?

std::lock_guard segfaults on construction?

I'm attempting to access a shared std::queue using a std::mutex and a
std::lock_guard. The mutex (pending_md_mtx_) is a member variable of
another object (whose address is valid). My code seems to be segfault'ing
on the construction of the lock_guard.
Any ideas? Should I be using a std::unique_lock (or some other object)
instead? Running GCC 4.6 (--std=c++0x) under Ubuntu Linux.
void enqueue_md(Packet* packet)
{
std::lock_guard<std::mutex> lock(pending_md_mtx_);
pending_md_.push(packet);
}
GDB Stacktrace:
(gdb) bt
#0 __pthread_mutex_lock (mutex=0x2f20aa75e6f4000) at pthread_mutex_lock.c:50
#1 0x000000000041a2dc in __gthread_mutex_lock (__mutex=0xff282ceacb40) at
/usr/include/c++/4.6/x86_64-linux-gnu/./bits/gthr-default.h:742
#2 lock (this=0xff282ceacb40) at /usr/include/c++/4.6/mutex:90
#3 lock_guard (__m=..., this=0x7f2874fc4db0) at
/usr/include/c++/4.6/mutex:445
#4 driver::Driver<Listener, false>::enqueue_md (this=0xff282ceac8a0,
packet=...) at exec/../../driver/Driver.hpp:95

No comments:

Post a Comment