-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问: "ReqInfoQueue" 队列的线程安全问题? #223
Comments
在一读一写的情况下是安全的 |
虽然这个队列是single producer --single cosumer 的, 如果没加锁,可能还是有内存序/可见性的问题吧 |
我认为还是后面的epoll_ctl 和网络线程中的epoll_wait 起了作用吧. |
为啥有问题?? |
epoll_ctl 对应了Realeas 语义, epoll_wait 对应了Acquire 语义, 所以当epoll_wait 返回后,能保证在epoll_ctl 之前对内存的修改可见,所以 ReqInfoQueue 这个队列就可以不用做任何处理 ; 否则 即使是最简单的 单生成者,单消费者队列,也要做相关的内存一致性模型的控制,才能保证data race free. |
如果你要讲系统调用有没有内存屏障的作用,那可能是有的。这篇文章讲了被抢占后,实际上store buffer会被排空https://pvk.ca/Blog/2019/01/09/preemption-is-gc-for-memory-reordering/
但他也说了,spsc的时候,x86的内存模型下,其实不需要屏障的。。which is always the case under the TSO memory model (including x86)。 比起上述的内存可见性讨论,我觉得更奇怪的点是:你用了一个线程间1-1无锁队列,却要求每次通知的时候要mod一下,陷入内核态,这似乎有点矛盾? |
The text was updated successfully, but these errors were encountered: