# std::this_thread::yield

> C++ Atlas: `cppatlas.com/w/cpp/thread/yield` | Source: https://en.cppreference.com/w/cpp/thread/yield | Domain: Concurrency support | Standards: C++11

Provides a hint to the implementation to reschedule the execution of threads, allowing other threads to run.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <thread>
void yield() noexcept; // (since C++11)
```

Provides a hint to the implementation to reschedule the execution of threads, allowing other threads to run.

### Parameters

(none)

### Return value

(none)

### Notes

The exact behavior of this function depends on the implementation, in particular on the mechanics of the OS scheduler in use and the state of the system. For example, a first-in-first-out realtime scheduler (`SCHED_FIFO` in Linux) would suspend the current thread and put it on the back of the queue of the same-priority threads that are ready to run, and if there are no other threads at the same priority, `yield` has no effect.

### Example

```cpp
#include <chrono>
#include <iostream>
#include <thread>

// "busy sleep" while suggesting that other threads run
// for a small amount of time
void little_sleep(std::chrono::microseconds us)
{
    auto start = std::chrono::high_resolution_clock::now();
    auto end = start + us;
    do
    {
        std::this_thread::yield();
    }
    while (std::chrono::high_resolution_clock::now() < end);
}

int main()
{
    auto start = std::chrono::high_resolution_clock::now();

    little_sleep(std::chrono::microseconds(100));

    auto elapsed = std::chrono::high_resolution_clock::now() - start;
    std::cout << "waited for "
              << std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count()
              << " microseconds\n";
}
```

Possible output:

```text
waited for 128 microseconds
```

### See also

- [C documentation for `thrd_yield`](https://en.cppreference.com/w/c/thread/thrd_yield)

---
Attribution: content from https://en.cppreference.com/w/cpp/thread/yield (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.