本文介绍了在sem_post(sem_t * sem)和sem_wait(sem_t * sem)周围是否有完整的内存屏障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在linux代码中,
我记得在mutex_lock()周围有一个完整的内存屏障。
我想确认它是否在sem_xxx周围。
In linux code,I remember hearing there is a full memory barrier around mutex_lock().I want to make sure whether it is around sem_xxx also.
推荐答案
是的,它使用原子递增/递减在无争议的情况下,当然有一个膜。对于有争议的情况,有一个系统调用futex,它也有一个membar。
Yes, it uses an atomic increment/decrement in the uncontended case, which of course has a membar. For the contended case there is a system call to futex, which also has a membar.
这篇关于在sem_post(sem_t * sem)和sem_wait(sem_t * sem)周围是否有完整的内存屏障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!