[Interest] QMutex and QTimer timeout

Francisco Ares frares at gmail.com
Tue Oct 7 13:43:42 CEST 2014


2014-10-07 1:42 GMT-03:00 Thiago Macieira <thiago.macieira at intel.com>:

> On Monday 06 October 2014 17:23:05 Francisco Ares wrote:
> > Hi,
> >
> > I'm trying to implement a serial communication class.  Under certain
> > conditions, I would like to send a message, then keep the thread locked
> > until some specific answer arrives, then the thread could be unlocked.
>
> Ok. It's usually a bad idea, but understood.
>
> Why can't you use QtSerialPort?
>
> > While testing the connection, the lock (using a QMutex for this) may lock
> > forever if the connection is opened, so I have implemented a single shot
> > QTimer so that the thread could have an exit point when this timer period
> > times out.
> >
> > But it does not work.
> >
> > The QMutex and the QTimer are on the same thread.  Does QMutex locks the
> > thread so much?  Any advice?
>
> Of course. The only thing that can take a mutex out of the lock() call is
> the
> lock succeeding.
>
> You can use tryLock() with a timeout, but then you have a race condition:
> the
> lock may have just become available an instant after the lock timed out,
> but
> before you could do anything.
>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>


Hi, and thanks for your answer.

Sorry, I should have put this on the original post.  I'm using Qt 4.8.5
(Gentoo distro), and "qextserialport" 1.2 (in fact, Gentoo developers are,
AFAIK, preparing for KDE 5, so Qt 5.X will be mainstream soon, so I'll port
everything to QSerialPort as well).

I will try the different suggested approaches, and, in any case, I'll post
the result.

Thanks to all,
Francisco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20141007/efcbd8e6/attachment.html>


More information about the Interest mailing list