Synchronization in the Linux kernel Knowledge

  
 

Q1. What is a critical section? What is the state of competition? What is synchronization?

A:

1) Critical regions are code segments for accessing and manipulating shared data. It is usually unsafe to access multiple resources concurrently with the same resource;

2) If two kernel tasks may be in the same critical section, it is an error phenomenon; if this happens, it is called a race condition;

3) Avoid concurrency and prevention The state of competition is called synchronization.


Q2. Briefly introduce deadlocks and ways to avoid deadlocks.

A: Deadlocks include deadlocks and ABBA deadlocks,

1) There are four reasons for deadlocks: exclusive use, non-preemption, request and hold, and loop wait;

2) The methods to avoid deadlocks are: destruction <;undistible<;conditions, destruction"request and hold"conditions, destruction "loop waiting" conditions.


Q3. What is the cause of concurrent execution in the kernel?

A: Concurrency" is divided into "pseudoconcurrency" and "true concurrency", and there are several reasons for concurrent execution in the kernel:

1 Interrupt: It may interrupt the currently executing code at any time;

2) Kernel preemption: Tasks in the kernel may be preempted by another task;

3) Sleep and its users Space synchronization: Processes executing in the kernel may sleep, which wakes up the scheduler and schedules a new user process execution;

4) Symmetric multiprocessing: two or more processors can execute simultaneously Code.


Q4. Give a definition of the semaphore and explain the meaning of down() and up().

A:

1) The semaphore in Linux is a sleep lock, which was proposed by Dijkstra in 1968. If a task tries to obtain a semaphore that has been held, The semaphore pushes it into the waiting queue and then lets it sleep; when the semaphore process releases the semaphore, a task in the waiting queue will be woken up, so that the semaphore can be obtained;

2) The semaphore supports two atomic operations P() and V(), the former is called the test operation, the latter is called the increase operation; later the system calls the two operations down() and up(); >

3) The down() operation requests a semaphore by decrementing the semaphore count by one; the up() operation is used to release the semaphore, which is also referred to as "up> (upping) semaphore Because it will increase the count value of the semaphore.

Copyright © Windows knowledge All Rights Reserved