1. Thread Concept
A process is an area of memory that contains some resources that the operating system uses to divide its work into functional units. A thread is an entity of a process, a basic unit of CPU dispatch and dispatch, and a basic unit that is smaller than the process to run independently. Threads do not own system resources themselves, but have very few resources (such as program calculators, a set of registers and stacks, etc.) that are essential for running, but share all the resources owned by the process with other threads that belong to one process.
In an application, a program has at least one process, and a process has at least one thread.
2, the advantages of multithreading
(1) Improve CPU utilization
(2) Improve the program response speed. Multithreading can divide application-related functions into multiple separate tasks and concurrently processing, without affecting the main thread running and improving the program response speed.
(3) The relative process overhead is small and easy to dispatch.
(4) Adjustable multi-threaded task priority, easy to improve the performance of the program.
3, the disadvantage of multithreading
(1) Waiting for a shared resource (primarily an exclusive resource, such as a printer) can cause the program to run slower.
(2) Multi-threaded management requires additional CPU overhead.
(3) Multi-threaded deadlock, long-time waiting resources and resource competition can cause thread deadlock easily.
(4) When reading or writing to the public variable, it is easy to cause the common variable data error due to different processing of multi-threading.
(5) The abnormal interruption of thread, it is easy to produce some errors we can not predict.
C # Multithreading series (i)