Processes, threads, and application domains
2015-06-15
Directory
1 process
1.1 Four basic features
1.2 Emergence of the process
1.3 Definition and characteristics of the process
1.4 Summary of the process
2 Threads
2.1 The appearance of a thread
2.2 Summary of Threads
3 application domain (AppDomain)
3.1 Emergence of application domains
3.2 Domain-to-thread relationships
3.3 Example: Executing code in another application domain
Reference:
1 process
Return
1.1 Four basic features
Processes are created and managed by the operating system, leaving the operating system out of the process, and first look at the four basic features of the operating system:
- Concurrency (Concurrence)
parallelism refers to the occurrence of two or more events at the same time, which is a microscopic concept, that is, physically these events occur simultaneously, while concurrency means that two or more events occur at the same time interval, which is a more macroscopic concept.
In a multi-channel program environment, concurrency refers to a period of time a multi-channel program at the same time, but in a single processor system, each moment can only execute a program, so micro-these programs are alternately executed. It should be noted that the usual procedures are static entities, which cannot be executed concurrently. In order for the program to execute concurrently, the system must establish a process for each program separately. A process, also called a task, is simply a basic unit that can run independently in a system and is allocated as a resource, and it is an active entity. Information can be executed and exchanged concurrently between multiple processes. A process requires a certain amount of resources, such as CPU, storage space, and I/O devices, to run at runtime. The purpose of introducing a process into the operating system is to enable the program to execute concurrently.
The so-called sharing means that the resources in the system can be used by multiple concurrent execution processes in memory. Because of the different properties of resources, multiple processes share different ways of sharing resources, can be divided into: mutually exclusive sharing method and simultaneous access mode
Refers to a physical entity that becomes a logical counterpart through technology. In the operating system virtual implementation is mainly through the use of time-sharing method. Obviously, if n is the number of virtual logical devices corresponding to a physical device, the speed of the virtual device must be the 1/n of the physical device speed.
- Asynchronous (Asynchronism)
In a multi-channel program design environment, allowing multiple processes to execute concurrently, due to the constraints of resources and other factors, usually, the process is not "one go", but the "walk-stop" way to run. It is unpredictable when each process in memory is executed, when it is paused, how it is pushed forward, and how much time each program takes to complete. Or, the process is running asynchronously. However, as long as the running environment is the same, the job runs multiple times and gets exactly the same result, so the asynchronous run is allowed.
1.2 Emergence of the process
The operating system produces a process in order for the program to execute concurrently.
1.3 Definition and characteristics of the process
Process definition: The process by which a program can execute concurrently on a data set.
Characteristics of the process:
- The dynamic process is the process entity's execution process, so the process has a certain life cycle. And the program is just a set of ordered instructions, and placed on some kind of media, itself has no meaning of operation, so the program is a static entity.
- Concurrency of
- Independence This means that the process entity is a basic unit that can operate independently, and is also the basic unit of the system to obtain resources and dispatch independently.
- of Asynchrony
- Structural features from the structure, the process entity is composed of the program section, the data section and the Process Control block three parts.
(Process Control block (PCB): A Process Control block is part of a process entity that records all the information required by the operating system to describe the process and to control the process's operation.) OS is based on the PCB to control and manage the concurrent execution of the process)
1.4 Summary of the process
- Definition: The process by which a program can execute concurrently on a data set, each of which has its own address space and a single control flow.
- Problem to solve: In order for the program to execute concurrently, (for concurrent execution, it is necessary to isolate the process, making the process independent, i.e. each process has its own data segment, program segment, Process control block)
In NET, each application is loaded into a separate process and a private virtual memory is specified for the process. The process cannot access physical memory directly, and the operating system maps these virtual memory to a region of physical memory or IO device through other processing, and there is no overlap between these physical memory, which determines that one process cannot access memory allocated to another process. Accordingly, an application running in that process cannot write to another application's memory, which ensures that any code that executes the error does not compromise an application other than its address space. Under this mechanism, the process as an independent and secure boundary between applications greatly improves operational security.
- The disadvantage of the process is that it reduces performance. Many processes that work together need to communicate with each other, and the process cannot share any memory, and you cannot use a memory pointer that is passed from one process to another process in any meaningful way. In addition, you cannot make a direct call between two processes. You have to use proxies instead, which provides some degree of indirection.
2 Threads
Return
2.1 The appearance of a thread
We first review the two basic properties of the process:
- Process enables an independent unit that can have resources
- The process is also a basic unit that can dispatch and dispatch independently.
Because of these two basic attributes, the process becomes a basic unit that can run independently, which forms the basis of concurrent execution of the process.
Because the process is the owner of a resource, the system must pay a significant time and space overhead in the process of creating, revoking, and switching. In order to solve this problem, a lot of operating system scholars think: The process of the two attributes separated from the operating system separately processed. That is, as the basic unit of dispatch and dispatch, not at the same time as the unit of independent allocation of resources, so as to make it run lightly, and the basic unit with resources, and do not frequently switch to it, under the guidance of this idea, produced the concept of threading.
Reason for threading: In order to reduce the time and space overhead of executing the program concurrently, the OS has better concurrency.
In an OS that introduces threads, a thread is an entity in a process (one or more instruction execution flows in a process), which is the basic unit that is dispatched and dispatched independently by the system. Threads basically no longer have system resources (only a few resources that are essential in the run, such as program counters, registers, and stacks), but it can share all the resources owned by the process with other thread functions belonging to one process. Line one thread can create and revoke another thread, and can execute concurrently between multiple threads in the same process.
a thread is an entity in a process that is the basic unit of dispatch and dispatch by the system , and the thread itself does not own system resources and has only a few resources that are essential to the operation, but it can share all the resources owned by the process with other threads of the same process. One thread can create and revoke another thread, which can be executed concurrently between multiple threads in the same process. Because of the mutual constraints between threads, the thread is running in a discontinuous. Threads also have three basic states of readiness, blocking, and running.
2.2 Summary of Threads
- Background: Because the process is the owner of a resource, in the process of creation, revocation, and switching, the system must pay a large amount of time and space overhead, limiting the further increase in concurrency.
- Problems to solve: during the process of creating, revoking, and switching processes, the system must pay a large space-time overhead.
- Workaround: Separate the two properties of the process and be handled separately by the operating system. Separate the "basic unit of dispatch and distribution" as a thread, and the process as the basic unit of the resource, and the thread as an entity in the process.
3 application domain (AppDomain)
Return
3.1 Emergence of application domains
In NET, the application has a new boundary: the application domain (hereinafter referred to as the domain). It is a virtual boundary that is used to isolate an application. Prior to the advent of. NET, only one application could run under a process, and after the net appeared, multiple applications could run under a process because of the presence of the application domain.
. NET structure, because the common language runtime can verify that the code is type-safe, it can provide the same level of isolation as the process boundary, with much lower performance overhead.
3.2 Domain-to-thread relationships
In. NET, a thread is the operating system construct that the common language runtime uses to execute code. At run time, all managed code is loaded into a domain and run by a specific operating system thread. However, there is no one by one correspondence between the domain and the thread. At any given time, more than one thread can be executed in a single domain, and a particular thread is not confined to a single domain. That is, threads can span domain boundaries and do not create new threads for each domain. Of course, at specified times, each thread can be executed in only one domain. The runtime keeps track of which threads are running in all domains. by calling. NET class library, you can also determine the domain in which the thread that is executing is located in the Thread.getdomain method.
3.3 Example: Executing code in another application domain
If you want to load the assembly into another application domain, you can use executeassembly or executeassemblybyname, or use one of the other overloaded versions of these methods to refer to executing code in another application domain (C # Programming Guide).
If you want to execute another assembly from a location other than the default entry point, you can define a new type derived from MarshalByRefObject in the remote assembly. Then use CreateInstance in your application to create an instance of that type, referencing access to objects across the AppDomain boundary.
Reference:
[1] Analysis of process, thread and application domain (AppDomain)
[2] Review lessons: Understanding of processes, threads, and application domains
Processes, threads, and application domains