[Qt-interest] How to block until posted event is processed?

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Mon May 31 11:27:37 CEST 2010


Mihail Naydenov wrote on Monday, May 31, 2010 11:03 AM:

> ...
> My question is: Is the above scenario possible (without some
> cross-wired wait conditions), 

What you are really trying to solve is the archetypical example of thread synchronisation, and unfortunatelly you probably won't get around solving this with the usual thread patterns. Read up on "barrier synchronisation" and co (e.g. start here: http://en.wikipedia.org/wiki/Barrier_%28computer_science%29).

The closest that Qt provides as a "barrier", after a quick documenation browsing, is the http://doc.trolltech.com/4.6/qfuture.html class (maybe together with the QFutureSynchronizer): "QFuture allows threads to be synchronized against one or more results which will be ready at a later point in time." - I think http://doc.trolltech.com/4.6/qfuture.html#result should do the job: "If the result is not immediately available, this function will block and wait for the result to become available."

An actual "barrier" implementation is available in boost: http://www.boost.org/doc/libs/1_33_1/doc/html/barrier.html - this one also allows to synchronise up to N threads. I am not aware that Qt offers such an implementation, too, which would be very useful (*hint* *hint* ;)

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list