79467264

Date: 2025-02-25 16:40:31
Score: 1.5
Natty:
Report link

I hence wonder, when threads are waiting for I/O operations, e.g., user input, network I/O, disk I/O, etc, is it guaranteed that they'll yield the CPU resources to others?

Not that I know of, at least, when the thread is doing non-blocking I/O or polling, such as repeatedly checking whether I/O is ready, it may remain active and consume CPU resources.

If the answer is not, is there any way forcing them to do so? I noticed The scheme shall be able to be achieved by C, low-level hacking is acceptable.

If your OS is UNIX, maybe sched_yield is what you are looking for, provided that you are well aware of under what scenarios the thread is supposed to yield.

Reasons:
  • Blacklisted phrase (1): is there any
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
Posted by: PkDrew