There is no generic method to know whether the counter-party, died, halted, partially locked (eg one of the threads is in an infinite loop), playing possum, or just being adversarial. If the counter-party is cooperative, you can communicate with heartbeats and rely on them to decide if it responsive.
The fact that your program is "stuck" attempting to lock a mutex (are you sure that that's the case?) can indicate that,
- the queue is empty, and the timeout value hasn't expired
- you've run into a deadlock scenario.
The timed_receive succeeds, times out, or throws as expected:
bool timed_receive(void * buffer, std::size_t buffer_size,
std::size_t & recvd_size, unsigned int & priority,
const boost::posix_time::ptime & abs_time);
Receives a message from the message queue. The message is stored in
buffer "buffer", which has size "buffer_size". The received message
has size "recvd_size" and priority "priority". If the message queue is
empty the receiver retries until time "abs_time" is reached. Returns
true if the message has been successfully sent. Returns false if
timeout is reached. Throws interprocess_error on error.
Also make sure you pass an absolute timeout value.