qt6-bb10/tests/auto/corelib/thread
Marc Mutz d6c8fab880 QMutex: make sure we try_lock_for no shorter than the duration passed
By templating on the <chrono> types and unconditionally using
duration_cast to coerce the duration into a milliseconds, we
allowed code such as

   mutex.try_lock_for(10us)

to compile, which is misleading, since it's actually a zero-
timeout try_lock().

Feedback from the std-discussions mailing list is that the
wait_for functions should wait for _at least_ the duration
given, because that is the natural direction of variance
(tasks becoming ready to run might not get a CPU immediately,
causing delays), while an interface that documents to wait
_no more_ than the given duration is promising something it
cannot fulfill.

Fix by converting the given duration to the smallest number
of milliseconds not less than the original duration. If that
is not representable in an int, use INT_MAX, emulating the
effect of a spurious wakeup, which are allowed to happen if
the function returns false in that case.

In the above example, the try_lock_for call is now equivalent
to

  mutex.tryLock(1);

The tryLock() docs state that the actual waiting time does
not exceed the given milliseconds, but fixing that is a
separate issue.

Change-Id: Id4cbbea0ecc6fd2f94bb5aef28a1658be3728e52
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2016-11-22 11:32:35 +00:00
..
qatomicint Add Intel copyright to files that Intel has had non-trivial contribution 2016-01-21 22:44:21 +00:00
qatomicinteger Merge remote-tracking branch 'origin/5.6' into 5.7 2016-03-24 20:37:33 +01:00
qatomicpointer Add Intel copyright to files that Intel has had non-trivial contribution 2016-01-21 22:44:21 +00:00
qfuture Updated license headers 2016-01-21 18:55:18 +00:00
qfuturesynchronizer Updated license headers 2016-01-21 18:55:18 +00:00
qfuturewatcher Updated license headers 2016-01-21 18:55:18 +00:00
qmutex QMutex: make sure we try_lock_for no shorter than the duration passed 2016-11-22 11:32:35 +00:00
qmutexlocker Updated license headers 2016-01-21 18:55:18 +00:00
qreadlocker Updated license headers 2016-01-21 18:55:18 +00:00
qreadwritelock Updated license headers 2016-01-21 18:55:18 +00:00
qresultstore Updated license headers 2016-01-21 18:55:18 +00:00
qsemaphore QtCore: Remove Windows CE. 2016-03-30 11:22:47 +00:00
qthread QtCore: Remove Windows CE. 2016-03-30 11:22:47 +00:00
qthreadonce QtCore: Remove Windows CE. 2016-03-30 11:22:47 +00:00
qthreadpool Add Intel copyright to files that Intel has had non-trivial contribution 2016-01-21 22:44:21 +00:00
qthreadstorage winrt: Make test functional 2016-08-09 12:13:23 +00:00
qwaitcondition Updated license headers 2016-01-21 18:55:18 +00:00
qwritelocker Updated license headers 2016-01-21 18:55:18 +00:00
thread.pro Replace the type-based QAtomicIntegerTraits with a size-based one 2014-01-30 18:06:27 +01:00