You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code paths that access and manipulate shared data are called critical regions (also called
critical sections).
并发原因
Interrupts— An interrupt can occur asynchronously at almost any time, interrupting the currently executing code.
Softirqs and tasklets— The kernel can raise or schedule a softirq or tasklet at almost any time, interrupting the currently executing code.
Kernel preemption— Because the kernel is preemptive, one task in the kernel can preempt another.
Sleeping and synchronization with user-space— A task in the kernel can sleep and thus invoke the scheduler, resulting in the running of a new process.
Symmetrical multiprocessing— Two or more processors can execute kernel code at exactly the same time.
写内核代码前需要问自己几个问题
Is the data global? Can a thread of execution other than the current one access it?
Is the data shared between process context and interrupt context? Is it shared between two different interrupt handlers?
If a process is preempted while accessing this data, can the newly scheduled process access the same data?
Can the current process sleep (block) on anything? If it does, in what state does that leave any shared data?
What prevents the data from being freed out from under me?
What happens if this function is called again on another processor?
Given the proceeding points, how am I going to ensure that my code is safe from concurrency?
死锁
A deadlock is a condition involving one or more threads of execution and one or more
resources, such that each thread waits for one of the resources, but all the resources are
already held.
死锁类型
ABBA 密码死锁应该遵循的规则
Implement lock ordering.
Prevent starvation.Ask yourself, does this code always finish? If foo does not occur, will bar wait forever?
The term lock contention, or simply contention, describes a lock currently in use but that
another thread is trying to acquire.
锁的作用是让系统顺序访问临界资源,因此锁很明显会拖慢系统。
Scalability is a measurement of how well a system can be expanded.
// TODO
The text was updated successfully, but these errors were encountered:
Critical Regions and Race Conditions
Code paths that access and manipulate shared data are called critical regions (also called
critical sections).
并发原因
写内核代码前需要问自己几个问题
死锁
A deadlock is a condition involving one or more threads of execution and one or more
resources, such that each thread waits for one of the resources, but all the resources are
already held.
死锁类型
ABBA
密码死锁应该遵循的规则
在锁代码上方添加获取锁顺序的注释是很好的实践。解锁的顺序与死锁无关,尽管通常的做法是按照与获取锁的顺序相反的顺序释放锁
Contention and Scalability
The term lock contention, or simply contention, describes a lock currently in use but that
another thread is trying to acquire.
锁的作用是让系统顺序访问临界资源,因此锁很明显会拖慢系统。
Scalability is a measurement of how well a system can be expanded.
// TODO
The text was updated successfully, but these errors were encountered: