2、导致进程无法杀死int mutex_lock_interruptible (struct mutex *lock);Same, but can be interrupted. If interrupted, returns a non zero value and doesn't hold the lock. Test the return value!!! 可以被中断int mutex_trylock (struct mutex *lock);Never waits. Returns a non zero valu
3、e if the mutex is not available.int mutex_is_locked(struct mutex *lock);Just tells whether the mutex is locked or not.无等待void mutex_unlock (struct mutex *lock);Releases the lock. Make sure you do it as quickly as possible! 2.Reader/writersemphopres读写信号量Allow sh
4、ared access by unlimited readers, or by only 1 writer. Writers get priority.允许有限数量的读访问,但是只能有一个写访问。void init_rwsem (struct rw_semaphore *sem);void down_read (struct rw_semaphore *sem);int down_read_trylock (struct rw_semaphore *sem);int up_read (struct rw_semaph
5、ore *sem);void down_write (struct rw_semaphore *sem);int down_write_trylock (struct rw_semaphore *sem);int up_write (struct rw_semaphore *sem);Well suited for rare writes, holding the semaphore briefly. Otherwise, readers get starved, waiting too long for the s
6、emaphore to be released. 3.Spinlocks自旋锁初始化:Staticspinlock_t my_lock = SPIN_LOCK_UNLOCKED;Dynamicvoid spin_lock_init (spinlock_t *lock);使用:void spin_[un]lock (spinlock_t *lock);Doesn't disable interrupts. Used for locking in process context(critical sections in
7、which you do not want to sleep).void spin_lock_irqsave / spin_unlock_irqrestore (spinlock_t *lock, unsigned long flags);Disables / restores IRQs on the local CPU.Typically used when the lock can be accessed in both process and interrupt context, to prevent pree
8、mption by interrupts 进程同步/通信1.Semaphore信号量简单过程:semaphoresv=1; loopforever{ P(sv); criticalcodesection; V(sv); noncriticalcodesection;}头文件以及函数:#includeintsem