Subject: [boost] [Thread] Assertion on mutex when using multiple threads and mutexes
From: Tim van den Kerkhof (tim.van.den.kerkhof_at_[hidden])
Date: 2011-07-22 10:46:04
As a part of a project I'm writing a logger function. This logger
function sends an e-mail when the program wants to log something. Since
it has happened that the SMTP server was non responsive, I've decided to
do the sending of the mails in a separate thread.
This thread reads messages from an std::deque which is filled by the
The thread is setup as follows:
bufferOverflow = mBufferOverflow;
mBufferOverflow = false;
nrOfItems = mEmailBuffer.size();
if (nrOfItems > 0)
emailItem = mEmailBuffer.front();
if (nrOfItems > 0)
bool sent = false;
..... Do something with the message .....
mLogFile << emailItem.mMessage << std::endl;
sent = true;
catch (const std::exception &e)
// Unable to send mail, an exception occurred. Retry
sending it after some time
sent = false;
The function log() adds a new message to the deque (mEmailBuffer) as
When the main program exits, the destructor of the logger object is
called. This is where it goes wrong, the application crashes with an error:
Assertion `!pthread_mutex_destroy(&m)' failed.
The destructor merely calls an interrupt on the thread and then joins it:
In the main program, I use multiple different classes which make use of
boost threading and mutex as well, could this cause this behaviour? Not
calling the destructor of the logger object results in no errors, as
does using the logger object and not doing anything else.
My guess is I am doing something very wrong, or there is a bug in the
threading library when using multiple threads divided over several classes.
Does anyone have a idea what the reason for this error might be?
Tim van den Kerkhof
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk