linux 两个驱动 竞争,Linux设备驱动第五章(并发和竞争)读书笔记(国外英文资料).doc...

Linux设备驱动第五章(并发和竞争)读书笔记(国外英文资料)

Linux设备驱动第五章(并发和竞争)读书笔记(国外英文资料)

The fifth chapter is concurrency and competition

Reference article: /u1/34474/showart.php? Id=408682?

5.3 flags and mutex

1) flag is the core of a single integer value. Combined with a pair of functions, also known as PV operations".

One wants to enter the critical section of the P process with the flag raised, if the flag value is greater than 0, this value decreased 1, and the process continues. If the flag is small than or equal to 0, indicating that the flag has been occupied by other processes, the process must wait until the flag is released.

Unlock the flag, flag is released, to complete the operation by calling the V V operation, increasing the value of the flag, and the flag can wake up waiting process.

2) mutex function is: mutual exclusion, to prevent multiple processes simultaneously in the same critical area. The mutex is initialized to 1 flags. Because that is initialized to 1, when the first process of P, 1>0, so the process can run at the same time, the flag value is 0, 1 decline, the second process to obtain the flag is used to access the critical section, but found that the flag value is 0, so the process can not run until the 2 release of the flag process 1.

5.3.1 implementation of the LINUX flag

1) to use the flag, must type contains . is related to the struct semaphore;

2) the flag: create a flag, then use sema_init to set it

Such as:

Struct semaphore *sem; / / define flag

Sema_init (SEM, Val); / / initialize Val to initialize the value of flag flag.

3) usually, flag is used to model the mutex. As a result, the kernel provides a series of macros to initialize.

DECLARE_MUTEX (name); / / initialize a mutex, a value of 1

DECLARE_MUTEX_LOCKED (name); / / initialize a mutex, a value of 0 is: flag after initialization is not available.

To use this flag any process must first unlock it again.

When we need to initialize at runtime (that is, dynamic creation), we use the:

Void init_MUTEX (struct semaphore

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值