Process and context switching and thread context switching What is the difference?

1, first of all, we need to thoroughly understand what is the context switch? (Interview questions)
Context switching is to switch from a current task to perform another task during execution. However, to ensure that the next from the correct position to continue, before the handover, will be on a mission to save the state.

2, then, need to understand the difference between processes and threads? (Online a lot, here a brief description)
1).A thread is part of the process.Process is a basic unit of resource allocation, is the basic unit is scheduled to run, is an example of a program executed; thread is the smallest unit of the process operation is performed, i.e., the basic unit of execution processor scheduling is a process flow of execution .
2).Different memory space. Each process has its own separate memory space, while the threads share the process memory space.
Process context switching thread context switching and the main difference is switched virtual memory space threads are the same (as are their own process), however, the process of switching the virtual memory space is different.
Meanwhile, two context switch processing is accomplished by the kernel Caozuoxitong. This handover process accompanied by the kernel most significant performance loss is switched out of the register contents.

3, thread context switching than the process context switch much faster.
Added: Multithreading is how to achieve?
Mainly by allocating CPU CPU time slice to each thread to achieve multi-threaded. Even the single-core processor (CPU) can perform multi-threaded processing.
CPU time slice is assigned to each thread of time, because time is very short piece, so the CPU by constantly switching threads execute, let's execute multiple threads simultaneously feeling, time slice is typically tens of milliseconds (ms).

4, during context switches, CPU time slice allocation algorithm to perform the task cycle time slice allocation algorithm in Java What?
The simplest and most common is based onRound-robin scheduling algorithm.Round-robin scheduling algorithm is very fair allocation of processors, each process can run only ready queue each time slice.
Principle: In the round-robin scheduling algorithm, the system according to the principle of first come, first served, all lined up ready process a ready queue, and every once in a while an interrupt is generated, the process scheduler to activate the system, to complete a deal machine scheduling, processors allocated to the first team ready queue process, let it execute instructions. When the end or the end of the time slice execution process, the system CPU will again be assigned to the first team process.

Published 451 original articles · won praise 17 · views 10000 +

Guess you like

Origin blog.csdn.net/zt2650693774/article/details/105193125