在 linux 代码中, 我记得听说 mutex_lock() 周围有一个完整的内存屏障。 我想确定它是否也在 sem_xxx 附近。
最佳答案
权威答案在这里:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_11
Applications shall ensure that access to any memory location by more than one thread of control (threads or processes) is restricted such that no thread of control can read or modify a memory location while another thread of control may be modifying it. Such access is restricted using functions that synchronize thread execution and also synchronize memory with respect to other threads. The following functions synchronize memory with respect to other threads: ...
sem_wait
和 sem_post
在列表中,所以它们是完整的内存屏障。
关于c++ - sem_post(sem_t * sem) 和 sem_wait(sem_t * sem) 周围是否存在完整的内存屏障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16431679/