|
Boost Users : |
Subject: Re: [Boost-users] [threads] Deadlock?
From: Jan Kundrát (jkt_at_[hidden])
Date: 2011-04-04 07:08:51
On 03/29/11 00:05, The Novice Coder wrote:
> The code deadlocks on this snippit:
>
> if( wait)
> {
> // lock the condition, add the event, wait for the condition, and
> get the return value!
> boost::mutex::scoped_lock lk(serviceMutex_);
> clearException();
> returnValue_ = 0;
> qApp->postEvent(temp_this, temp_event, Qt::HighEventPriority);
> serviceCondition_.wait(lk);
> }
>
> Where wait is specified by the caller to wait for the other thread to
> return. In the service request thread has this snippet:
>
> {
> boost::mutex::scoped_lock lk( serviceMutex_);
> returnValue_ = qtService(s->getCommand());
> serviceCondition_.notify_one();
> }
First of all, I wonder what your reason is to go with boost's threading
over Qt's facilities, given that your application is already tightly
bound into using Qt (you're using their event loop and events).
Are you sure that the Qt's event loop is running? Are both threads
executing their own event loop? (You should check this one, it depends
on you if you want each thread to run an event loop, or do something
else. In any case, make sure you understand the semantics of
QCoreApplication::postEvent and how these events are delivered).
Finally, you code is missing some context to understand what you're
trying to achieve. I have no idea what the "qtService" stands for, not
what "s" is, if there are any classes derived from the QObject, how you
intend to use the events, etc etc.
Cheers,
Jan
-- Trojita, a fast e-mail client -- http://trojita.flaska.net/
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