Basics of Linux: kernel synchronization

Source: Internet
Author: User
Q1. what is a critical section? What is competition? What is synchronization? A: 1) the critical section (criticalregions) is the code segment for accessing and operating shared data. it is usually unsafe for multiple kernel tasks to concurrently access the same resource. 2) if the two kernel tasks may be in the same critical section...

Q1. what is a critical section? What is competition? What is synchronization?
A:

1) the critical section (critical regions) is the code segment for accessing and operating shared data. it is usually unsafe for multiple kernel tasks to concurrently access the same resource;

2) if two kernel tasks may be in the same critical section, it is an error. if this happens, it is called a competitive state;

3) synchronization is used to avoid concurrency and prevent competition ).

 

Q2. a brief introduction of deadlocks and methods to avoid deadlocks.

A: deadlocks include self-deadlocks and ABBA deadlocks,

1) There are four reasons for deadlock: mutual exclusion, non-preemption, request and persistence, and cyclic waiting;

2) methods to avoid deadlocks include: cracking the "irrevocable" conditions, breaking the "request and persistence" conditions, and damaging the "cyclic waiting" conditions.

 

Q3. what causes concurrent execution in the kernel?

A: "concurrency" can be divided into "pseudo concurrency" and "real concurrency". there are several causes of concurrent execution in the kernel:

1) interrupt: it may interrupt the code currently being executed at any time;

2) kernel preemption: tasks in the kernel may be preemptible by another task;

3) sleep and its synchronization with the user space: processes executed in the kernel may sleep, which will wake up the scheduler and schedule a new user process to execute;

4) symmetric multiple processing: two or more processors can execute code simultaneously.

 

Q4. defines the semaphores and describes the meanings of down () and up.

A:

1) semaphores in Linux are sleep locks, which were proposed by Dijkstra in 1968. if a task tries to obtain a hold semaphores, The semaphores push them into the waiting queue, then let it sleep; when the process holding the Semaphore releases the semaphore, a task in the waiting queue will be awakened to obtain the Semaphore;

2) semaphores support two atomic operations: P () and V (). The former is called a test operation, and the latter is called a ADD operation. later, the system calls the two operations down () respectively () and up ();

3) The down () operation returns a semaphore by subtracting 1 from the semaphore count. the up () operation is used to release the semaphore, which is also called a upping semaphore, because it increases the count of semaphores.

From: Column of zhouzxi

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.