1// Copyright (C) 2023 The Qt Company Ltd.
2// Copyright (C) 2023 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
9 \relates QAtomicInteger
10 //! \relatesalso QAtomicPointer
13 Pauses the execution of the current thread for an unspecified time, using
14 hardware instructions, without de-scheduling this thread. This function is
15 meant to be used in high-throughput loops where the code expects another
16 thread to modify an atomic variable. This is completely different from
17 QThread::yieldCurrentThread(), which is an OS-level operation that may take
18 the whole thread off the CPU and allow other threads (possibly belonging to
19 other processes) to run.
33 This is useful both with and without hardware multithreading on the same
34 core. In the case of hardware threads, it serves to prevent further
35 speculative execution filling up the pipeline, which could starve the
36 sibling thread of resources. Across cores and higher levels of separation,
37 it allows the cache coherency protocol to allocate the cache line being
38 modified and inspected to the logical processor whose result this code is
41 It is also recommended to loop around code that does not modify the global
42 variable, to avoid contention in exclusively obtaining the memory location.
43 Therefore, an atomic modification loop such as a spinlock acquisition
48 while (!readOnlyCondition(atomic))
55 On x86 processors and on RISC-V processors with the \c{Zihintpause}
56 extension, this will emit the \c PAUSE instruction, which is ignored on
57 processors that don't support it; on ARMv7 or later ARM processors, it will
58 emit the \c{YIELD} instruction.