比如说,我cpu有四个线程,那么运行一个只能利用单线程的软件为什么不是这个进程把第一个核心的所有资源占用,而是每个线程占用百分之25?
黄舟2017-04-18 09:54:36
What you want can be achieved. There are different APIs that can be called on different operating systems. On Linux, sched_setaffinity is called. On Windows, SetProcessAffinityMask can be used. This is to bind a specific thread to run on a specific CPU. run on the core. Of course, what you said is that a thread completely occupies all the running of a CPU. This cannot be realized in the user mode. The current operating system schedules the program out; the kernel mode can run, but you have to actively schedule it yourself. Otherwise , the entire machine will appear in suspended animation, and the machine will not respond, but it is actually an infinite loop.
高洛峰2017-04-18 09:54:36
Modern operating systems operate the CPU using a preemptive multi-threading mechanism. When acquiring CPU control, a time slice is obtained, and after the time slice ends, the control is handed over to other threads.
天蓬老师2017-04-18 09:54:36
Home PC is a time-sharing system, which uses time slice rotation to evenly allocate resources. What should I do if a single thread monopolizes the entire CPU core and the thread loops endlessly