In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what the basic concept of multithreading in C#is. The quality of the article is high. Therefore, Xiaobian shares it with you as a reference. I hope you have a certain understanding of related knowledge after reading this article.
A process is a basic concept in Windows that contains the resources needed to run a program. A running application is considered a process in the operating system, and a process can consist of one or more threads. Threads are the basic unit of processor time allocated by an operating system, and there can be multiple threads executing code simultaneously in a process. Processes are relatively independent, one process cannot access the data of another process (unless distributed computing is used), the failure of one process does not affect the operation of other processes, and Windows systems use processes to divide work into multiple independent areas. A process can be understood as the basic boundary of a program. Is a running routine of the application, is a dynamic execution process of the application.
thread
Thread is the basic unit of execution in a process, and is the basic unit of CPU time allocated by the operating system. A process can contain several threads, and the first thread executed at the process entrance is regarded as the main thread of this process. In. NET applications, the entry point is the Main() method, which automatically creates a main thread when called. Threads are mainly composed of CPU registers, call stacks, and thread local storage (TLS). CPU registers mainly record the status of the currently executed thread, call stack is mainly used to maintain the memory and data called by the thread, TLS is mainly used to store the status information of the thread.
multithreading
Advantages of multithreading: multiple tasks can be completed at the same time; the program can be more responsive; tasks that take up a lot of processing time or tasks that are not currently being processed can be periodically given processing time to other tasks; tasks can be stopped at any time; priority of each task can be set to optimize program performance.
So one might ask: Why multithreaded execution? To sum up, there are two reasons:
1, CPU running speed is too fast, hardware processing speed can not keep up, so the operating system for time slice management. Thus, from a macro point of view is multithreaded concurrency, because the CPU speed is too fast to notice, it seems that the same time to perform different operations. But microscopically, there can only be one thread at a time.
At present, computers are multi-core multi-CPU, a CPU can only run one thread at the same time, but multiple CPUs can run multiple threads at the same time.
However, while multithreading has many advantages, it must also be recognized that multithreading may have disadvantages that affect system performance in order to use threads correctly. The disadvantages include the following:
(1) Thread is also a program, so threads need to occupy memory, and the more threads, the more memory they occupy.
(2) Multithreading requires coordination and management, so it takes CPU time to track threads.
(3) Access to shared resources between threads will affect each other, and the problem of contention for shared resources must be solved.
(4) Too many threads lead to too much control complexity, which may eventually lead to many program defects.
When an executable program is started, a main thread is created. By default, a C#program has a thread that executes code in the program that begins and ends with the Main method, and every command executed directly or indirectly by the Main () method has a default thread (the main thread) that also terminates when the Main () method returns.
What is the basic concept of C#multithreading to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.