Relationship between processes and threads:
There is a classic figure on the Internet that allows us to understand the relationship between processes and threads:
The following figure shows a two-way multi-lane road. If we regard the whole road as a "process, in the figure, the lanes separated by the white dotted lines are all "Threads" in the process.
This figure from: http://www.blogjava.net/pengpenglin/archive/2008/09/02/226292.html
Notes:
- These threads (lanes) share the public resources (land resources) of processes (roads ).
- These threads (lanes) must depend on processes (roads). That is to say, a thread cannot exist without a process (just like leaving the road, the lanes do not make sense ).
- These threads (lanes) can be concurrently executed (the lanes you walk you, I walk my), or synchronized with each other (some lanes are not allowed to move forward or turn when the traffic lights are on, you must wait for the vehicle passing through the other lanes ).
- These threads (lanes) rely on the Code logic (traffic lights) to control the operation. Once the code logic control is incorrect (deadlocked, multiple threads compete for unique resources at the same time), the thread will be in disorder, unordered.
- It is unknown who runs between these threads (lanes). It can be known only when the threads are allocated to the CPU time slice (traffic light changes.
Thread lifetime
After a thread is scheduled to be executed, the thread goes through several States, including not started, activated, and sleep, such as the lifetime of the displayed thread:
This figure is from "c # thread Reference Manual", the electronic version of this book has been downloaded in CSDN: http://d.download.csdn.net/down/1493065/phs415
If Java is used, it is easier to look at the figure below. In fact, they describe exactly the same:
JVM and process, thread
All programs written in Java Run in the java Virtual Machine (JVM). Every time a java application is started with a Java command, a JVM process is started. In the same JVM process, there is only one process itself. In this JVM environment, all program code runs in threads. The JVM finds the main () entry point of the program, and then runs the main () method. This produces a thread, which is called the main thread. After the main method is completed, the main thread runs completely. The JVM process also exits.
As shown in:
For more information, see:
Introduction to JVM and JRE
Http://blog.csdn.net/liufeng_cp/archive/2008/07/18/2674317.aspx
Java multi-thread programming Summary
Http://lavasoft.blog.51cto.com/62575/27069
Java has to consider cross-platform, so its process and thread model are relatively simple, and. Net is more complicated:
. Net CLR, process, application domain, thread
Note:
- Similar to a Java virtual machine, the CLR currently exists in a process, that is, the process loads the CLR. In.. Net 4.0 can coexist in the process. net 4.0 and earlier versions are a typical scenario (. net 4.0: "In-Proc SxS ).
- . Net introduces the application domain concept, which is a further logical partition in the process. Obviously, a process can contain multiple application domains, and each application domain carries one. NET executable program. Benefits:
- The application domain is a key feature of the operating system independence of the. NET platform. This logical partition abstracts the differences between different operating systems for loading executable programs.
- Compared with a complete process, the CPU and memory usage of the application domain is much smaller. Therefore, CLR loads and detaches application domains much faster than the complete process.
- Application domains provide deep isolation for hosted applications. If one application domain in the process fails, other application domains will remain normal.
The following figure shows the location of the application domain:
See: CLR thoroughly parses in-process Parallelism
References:
Explore Java Virtual Machine
Http://www.chinaaspx.com/comm/dotnetbbs/Showtopic.aspx? Forum_ID = 33 & Id = 302411 & PPage = 1
Process threads and some common multithreading concepts
Http://www.cnblogs.com/ChrisWang/archive/2009/09/07/1563675.html
. Net Discovery series 5-in-depth introduction to. Net real-time compilation mechanism (I)
Http://www.cnblogs.com/isline/archive/2009/12/22/1629831.html
Linux thread Analysis
Http://blog.chinaunix.net/u2/87597/showart.php? Id = 2178432
Features of running Azure Cloud Application
Http://tech.ccidnet.com/art/1105/20090625/1808497_1.html
Reading experience-programmer-C # thread Reference Manual (multi-thread Technical Analysis)
Http://www.cnblogs.com/lzhdim/archive/2009/11/27/1611510.html
Basic knowledge of multi-thread programming
Http://www.blogjava.net/pengpenglin/archive/2008/09/02/226292.html
Java multi-thread programming Summary
Http://lavasoft.blog.51cto.com/62575/27069