C # Multithreading series (i)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.