Operating system summary

Source: Internet
Author: User

The thread is introduced to reduce the time-space overhead of the Program During Concurrent execution, so that the OS has better concurrency.
Comparison between threads and processes
1) Scheduling
In traditional operating systems, processes are the basic unit of resource allocation and the basic unit for independent operation and scheduling. In the OS where threads are introduced, the process is still the basic unit of resource allocation, and the basic unit of independent running and scheduling is the thread. The thread can only work with a small amount of resources it needs.
2) Switch
In the OS where threads are introduced, in the same process, thread switching does not cause process switching, but switches from the thread in one process to the thread in another process, you need to switch the process.
3) concurrency
In the OS where threads are introduced, not only can concurrent execution be performed between processes, but also multiple threads in a process can be concurrently executed, so that the OS has better concurrency, in this way, the system resource utilization and system throughput can be improved more effectively.
4) possess resources
Process is the basic unit for resource allocation, whether it is a traditional OS or a thread-based OS. Generally, a thread does not own system resources (it is only essential for running), but it can access the process resources it belongs. All threads in a process can use all resources of the process.
5) system overhead
When creating or revoking a process, the system must create and recycle process control blocks for them to allocate or recycle resources, the overhead of the OS is much higher than the overhead required when the thread performs the same operation.

Semaphore mechanism
1) semaphore mechanism is a process synchronization mechanism proposed by Dijkstra to solve the process synchronization problem. There are four types: integer semaphores, record semaphores, and semaphores, and semaphores.
The integer semaphores mechanism requires resources to be requested through wait operations. When used up, the signal operation is used to release the resources. These two operations are atomic operations, therefore, it does not comply with the four principles of the synchronization mechanism that allows the right to wait.
2) in order to solve the problem that the integer semaphore mechanism cannot allow the right to wait, an improved record-type semaphore is proposed. The specific implementation is to store processes that cannot obtain resources through a block queue, the absolute value indicates the number of processes in the waiting queue because the resource is missing. If this type of resource cannot be obtained, discard the processor to enter the blocking queue. When there are idle resources, check whether there are waiting processes in the blocking queue.
3) and semaphores are proposed for a process that requires multiple resources. If two processes a and B require two resources C and D, but a first obtains C, B first obtains D, and then the deadlock occurs because they do not want to be released. And semaphore mechanism is to allocate all or all resources required by a process (as long as one of the resources is not idle)
4) the semaphore set mechanism is proposed for multiple processes that require multiple resources. It is the master of the above synchronization mechanism.
The general form is: swait (S1, T1, D1,... sn, TN, DN) where S is the semaphore, D is the demand value, T is the lower limit. Because it is an extension of the and-type semaphores, it is either completely allocated or not allocated.
 
Http://wenku.baidu.com/view/a1cb31671ed9ad51f01df2fa.html of Program Execution Process

There are three types of Processor Scheduling: Advanced scheduling, intermediate scheduling, and low-level scheduling.
1) Advanced scheduling refers to Job Scheduling. It refers to calling out-of-village jobs in the backup queue into memory based on an algorithm, and scheduling objects are jobs.
2) low-level scheduling is process scheduling. The scheduling object is the process, which is used to determine which process in the ready queue should obtain the processor. Then, the allocation program executes the specific operation to allocate the processor to the process.
3) Intermediate scheduling is the swap function in memory management. It aims to improve memory utilization and system throughput.

Conditions for deadlock
1) mutex condition: the process exclusively uses the allocated resources. That is, a resource can only be used by one process requesting the resource. Other applicants can only wait.
2) request and retention conditions: when a process has maintained one resource and needs another resource but cannot meet it, it is blocked, but the acquired resources are not released.
3) Non-deprivation condition: the resources obtained by the process cannot be deprived before they are used up. They can only be released by themselves after use.
4) loop wait condition: When a deadlock occurs, there must be a loop of resource competition.

Basic methods for handling deadlocks
1) prevent deadlocks. By setting constraints, you can destroy one or more conditions of the four conditions that generate a deadlock. However, due to the strict restrictions, the system's resource utilization and throughput may be affected (decreased ).
2) avoid deadlocks. It is also a pre-prevention policy. Some security algorithms are used to prevent the system from entering an insecure state, and the restrictions are weak. (Banker algorithm)
3) detect deadlocks. Do not take any restrictive measures in advance to allow the system to experience deadlocks during operation. However, the system's detection mechanism can detect the deadlock information and take corresponding measures to lift the deadlock.
4) Remove the deadlock. Used with Deadlock Detection. It is difficult to implement.

Deadlock Theorem
A sufficient condition for s to be in a deadlock state is that resource distribution diagrams in S state cannot be completely simplified.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.