Does a thread waiting on IO also block a core?

后端 未结 4 1252
眼角桃花
眼角桃花 2020-12-24 03:01

In the synchronous/blocking model of computation we usually say that a thread of execution will wait (be blocked) while it waits for an IO task to complete.

4条回答
  •  抹茶落季
    2020-12-24 03:52

    For most programming languages, used in standard ways, then the answer is that it will block your thread, but not your CPU.

    You would need to explicitely reserve a CPU for a particular thread (affinity) for 1 thread to block an entire CPU. To be more explicit, see this question:

    You could call the SetProcessAffinityMask on every process but yours with a mask that excludes just the core that will "belong" to your process, and use it on your process to set it to run just on this core (or, even better, SetThreadAffinityMask just on the thread that does the time-critical task).

提交回复
热议问题