Thread basics, java multithreading Basics
Why does Windows support threads?
In early computers, OS had no thread concept. The whole system was running a single thread, and CPU resources were occupied by one thread. You could only process one
Computing tasks, such as processing and printing a single task or some other computing tasks, when a BUG occurs in the task, the program stops responding. The processing method is to restart the machine,
To solve this problem, MicroSoft Windows NT, an operating system based on multithreading technology, has developed. Windows NT is the Windows
OS.
Process: the abstract concept refers to the set of resources to be used by an application.
Thread: virtualization of the CPU. Windows provides a dedicated thread for each process (a dedicated CPU concept abstracted by CPU fragments ).
Thread Overhead:
1. Thread Kernel Object
2. Thread environment Block
3. User Module Stack
4. Kernel Mode Stack
5. DDL thread link AND thread separation (Attach AND detach)
Thread usage reasons:
1. responsiveness.
Windows provides its own thread for each process to ensure that the application will not block other applications when an endless loop occurs. In GUI applications, you can hand over some work
A single thread enables the GUI thread to respond to the user sensitively without freezing previous windows programs.
2. Performance
Because each CPU in Windows schedules one thread and multiple CPUs can execute these threads concurrently, fully mobilize the CPU computing capability and concurrent operations can significantly improve applications.
Performance.
Type of CLR threads
1. Foreground thread: Execute the task that the system really wants to execute. For example, if I want to write an article, for example, the thread that handles the writing is the foreground thread.
2. Background threads: non-critical tasks, such as spelling checks performed by the system when writing an article.
using System;using System.Threading;namespace BackGroundTreadTest{ class Program { static void Main() { Thread t = new Thread(Worker); t.IsBackground = true;//Change it to a background Thread t.Start(); Console.WriteLine("Main Thread....."); } private static void Worker() { Thread.Sleep(10000); Console.WriteLine("Working...."); } }}
This section paves the way for Asynchronous Parallel programming as the basic concept of operating system threads.