Date: 2014.06.25
Location: Basic
-------------------------------------------------------------------------
First, brief
Process and thread threads are the basic concepts of the operating system. Abstract and important. Here are a few ways to analyze the differences between processes and threads.
-------------------------------------------------------------------------
Second, analysis
A process can be thought of as an instance of the program runtime . Is the system's independent entity for resource allocation , each process has a separate address space , so a process cannot directly access the variables and data structures of a process. Suppose you want a process to access the resources of a process that need to use interprocess communication, for example: Shared storage systems, messaging systems, pipeline communication systems, and so on.
A process can have more than one thread, and each thread uses the stack space it belongs to. The most basic differences between threads and processes are:multiple threads in the same process share some state, that is, multiple threads are able to read and write the same piece of memory. In other words, the memory space of the process is shared. Each thread is able to use these shared memory,Of course. There are also some shared memory threads that are shared between threads though. But each thread needs to repel each other or meet certain conditions to interview.
So there is a mutual exclusion lock, to prevent the same time to a thread to read and write a piece of memory area. Some memory can only be used for a fixed number of threads. Like a room definition can only accommodate n people, the solution is to hang n the key at the door. Every time you go in, take one. When you come out, put the key back, and once someone in the back wants to go in, the key shelf is empty. You have to wait in line at the door. This is the semaphore . To ensure that multiple threads do not conflict, mutually exclusive locks are a special case of semaphores (n=1), so the latter can be used instead of the predecessor, but mutually exclusive locks are simple and efficient. In scenarios where the resource monopoly must be guaranteed. We use mutually exclusive locks.
, and a process is unable to directly access the memory of a process. At the same time, each thread has its own registers and stacks, and other threads are able to read and write these stack memory.
A thread is a specific running path to a process. When a thread changes a resource in a process. Its sibling threads are able to see this change immediately.
-------------------------------------------------------------------------
Iii. Summary1. A process is the basic unit in which the system allocates resources. There is a separate memory address space, the thread is the basic unit of CPU scheduling, there is no separate address space, there is a separate stack. Local variables. Registers and program counters, and so on.
2. The cost of creating a process is large, including the need for a large amount of system resources to create a virtual address space, and a small overhead to create a thread. Basically there is only one kernel object and one stack.
3. Method that cannot directly access the processing resource as well as the method of sharing resources within multiple threads of the same process
4. This process switches overhead, thread switching overhead, overhead of interprocess communication, and small communication overhead between threads.
5. Threads belong to the process, you cannot operate independently, each process has at least one thread, which is the main thread.
The difference between a process and a thread