1

Some relevant discussion: Is std::this_thread::yield any different from sched_yield on linux?

I'm Wondering:

  1. this_thread::yield() usually needs to switch from user mode to kernel mode
  2. volatile pause still remains in user mode, but cpu pauses for ~30 clocks.

So, yield is more expensive than pause.

Wonder if the above understandings are correct?

I am trying to understand how yield and pause work internally.

Fyx
  • 174
  • 8
Gardener
  • 11
  • 1
  • 1
    `this_thread::yield()` gives up any remaining time-slice and waits for the OS to reschedule the thread. From [here](https://stackoverflow.com/a/37065332/3370124) _"...`_mm_pause` (the intrinsic for `pause`) won't release CPU for scheduler..."_ – Richard Critten Dec 24 '22 at 18:59
  • is yield() more expensive than mm_pause then? – Gardener Dec 24 '22 at 19:03
  • 2
    Defined expensive as the 2 operations do different jobs. One reschedules the thread the other pauses the thread but still holds onto the CPU resource (like a busy-wait). – Richard Critten Dec 24 '22 at 19:04
  • 1
    An interesting issue. Not usually worrying about performance when I'm yielding a thread. – user4581301 Dec 24 '22 at 19:38

0 Answers0