Matthias Nagorni schrieb am 22. Februar 2012 10:50
> RobertF schrieb am 21. Februar 2012 17:03
>
> > Thema "spurious wakeups": unter Linux (und sicher auch anderen
> > Systemen mit pthreads) wird Dein Code damit Probleme bekommen
> > (Hintergründe s. http://en.wikipedia.org/wiki/Spurious_wakeup).
>
> Abgesehen davon, dass wir hier über Qt reden und nicht pthreads, geht
Okay, da hast Du Recht, QWaitCondition kümmert sich schon darum (auch
wenn das intern einen weiteren, zusätzlichen Mutex erfordert...).
> es bei spurious wakeups darum, dass in seltenen Fällen mehr als ein
> wartender Thread aufgeweckt werden könnte, siehe
> http://pubs.opengroup.org/onlinepubs/009604499/functions/pthread_cond
> _signal.html
>
> Da im Beispiel sowieso immer alle Frame-Threads gleichzeitig
> aufgeweckt werden, wäre das hier keinerlei Problem.
Falsch, spurious wakeups können jederzeit auftreten, die Ursachen
sind komplizierter...
Die Empfehlung lautet:
In general, whenever a condition wait returns, the thread has to
re-evaluate the predicate associated with the condition wait to
determine whether it can safely proceed, should wait again, or should
declare a timeout. A return from the wait does not imply that the
associated predicate is either true or false.
It is thus recommended that a condition wait be enclosed in the
equivalent of a "while loop" that checks the predicate.
http://pubs.opengroup.org/onlinepubs/009604499/functions/pthread_cond
_wait.html