threadpool - Thread pools and context switching (tasks)? -


This is a fairly common computer science question and is not specific to any OS or framework

I'm a bit confused with the overhead associated with task switching on a thread pool. In many cases, this does not have to mean to give every task to its specific thread (we do not want to make too many hardware threads), so we put these tasks into actions that can be determined to run on a thread. We set up a pool of threads and then dynamically allocate the work to run on threads taken from the thread pool.

I'm just a bit confused on the overhead associated with switching functions (in a thread pool) (no answers can be found in depth). A DrDobbs article (sourced below) tells this, but I need to answer in depth what exactly is going on (a quote-qualified source would be fantastic :)).

  As per the definition, some work should be queued in the pool and then run on a separate thread from the original thread. This means that we essentially put the overhead and a reference switch in line to move the work into the pool. If we need to communicate with the original thread, such as through the message or in the future or similar, we will switch to another reference for this.   

Which components of thread are actually switching? The thread itself is not actually switching, just what is the upper part associated with this (more, less or one) data that is specific to the thread?

Source:

Let's first clarify the 5 key concepts and then discuss How they are correlated in a thread pool context:

  • Thread: A brief restart can be described in the program execution context, which is being run by code Given, data in CPU registries and stack When a thread is created, it is assigned to the code that should be executed in that thread context. In each CPU cycle, a command to execute the thread and data in the CPU registries and the stack in a given state.

  • Functions: This unit represents a unit of work that is assigned to a thread to execute.

  • Context switch (from Wikipedia): The process of storing and restoring the state (reference) of a thread is again from the same point in time after that execution. It can be started, it enables many processes to share a single CPU and is an essential feature of the multitasking operating system. Whether the reference has been formed, as mentioned above, the code that is being executed, CPU registries and stack.

    What is the context switch? Thread job represents only the peace of the act, which can be assigned to a thread to execute. Thread pool (from Wikipedia): There are thread threads in computer programming, where many threads are created to run a number

  • Thread Pool Line: Where to perform tasks by Threads in the pool The work is done. This data structure is a shared peace of memory where Threads can compete in the queue / decay, causing controversy in high load scenarios.

    And schedule it to execute in the thread pool.

  • The queue is queued in the work thread pool.
  • When a thread from the pool dequeues a task from the pool it executes and it starts to execute.
  • There is no free cpus to execute the thread from the pool, the operating system prevents a thread from executing a thread (depending on the thread scheduler policy and thread preferences) at some point, the other thread Reference switching.

    The operating system can stop the execution of a thread at any time, the reference switches to the second thread, returns back later to return, where it stops.

    The upper part of the switching switch is enhanced, when the number of active threads increases for pets, in this way, ideally, the minimum for capturing all the available CPUs in a thread pool machine. Tries to use the necessary threads.

    If your actions do not have a code that blocks something, context switching is reduced because it is not used more threads than the CPU available on the machine.

    Of course if you have only one core, then your main thread and thread pool will compete for the same CPU.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

Matlab: Transfer variable from GUI to Base Workspace and new Variables (Static Workspace, Script, Creating new Variables) -