A
A
arthur_veber2018-09-07 11:41:51
Multithreading
arthur_veber, 2018-09-07 11:41:51

Multithreading. How does the OS choose a kernel?

Let's say the processor has 2 cores.
We are writing a program for 2 threads.
Will they exactly be executed on 2 cores, that is, in parallel?
What if the first core is currently heavily loaded, the OS sends our first thread to a less loaded core - the second one, sees that the second core is still unloaded, waits until our first thread is executed and sends the second one there?
That is, even in a multi-core system, our multi-threaded application will not benefit?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
sunblossom, 2018-09-07
@sunblossom

Yes. Asynchronous is just a request from the OS to execute the code multithreaded. On which cores to perform the task, it will already decide itself according to the circumstances.

E
Elios, 2018-09-07
@strelov1

These two processes are far from the only processes that need to be performed in the system. Decides what and how much to load the task scheduler into the processor. In the book Tanenbaum - Modern operating systems, this topic is well disclosed.

X
xmoonlight, 2018-09-08
@xmoonlight

Do not specify explicitly - the kernel is chosen by the system.
Specify explicitly - the specified kernel will be used for a specific thread.
PS: this can be done even on client-side JS, in the browser, without any plugins: navigator.hardwareConcurrency

S
sim3x, 2018-09-08
@sim3x

How was it
https://www.itprotoday.com/windows-8/how-windows-n...
The NT dispatcher determines the order in which threads run and on which processors they run. Affinity is the tendency for a thread to run on a particular processor or set of system processors. NT uses soft affinity by default, running a thread on the same processor it ran on previously. NT also supports hard affinity to let you specify which processors a process or thread uses. Ideal affinity or preferred affinity lets you specify a preferred processor from the group of hard affinity processors. The NT dispatcher runs a process on the preferred processor if that processor is available. NCR's SMP Utilization Manager lets you set hard affinity and preferred affinity for process threads. Thus, a process can run on only a few processors, and the other processors remain free to run other processes.
Like now
https://docs.microsoft.com/en-us/windows/desktop/p...

We are writing a program for 2 threads.
Will they exactly be executed on 2 cores, that is, in parallel?
absolutely synchronously - no. Somehow in sync - yes
What if the first core is currently heavily loaded, the OS sends our first thread to a less loaded core - the second one, sees that the second core is still unloaded, waits until our first thread is executed and sends the second one there?
quite. I suppose that in this case, the dispatcher can shuffle your two threads a couple of times so that the difference between their endings will not exceed a couple (tens) of instructions
That is, even in a multi-core system, our multi-threaded application will not benefit?
if it is wrong to configure the dispatcher - yes. Theoretically, it is even possible to achieve a situation where your program will never finish running
the PS: all conclusions are based on my logic and may be incorrect. This information was obtained by googling and reading

P
Papayaved, 2018-09-13
@Papayaved

Depends on OS and processor. In processors where there are many cores or there are DSP cores, the developer usually chooses the cores on which tasks will work. It is necessary to use the processor and OS for realtime systems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question