zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.67k stars 2.35k forks source link

Consumer threads can never be awakened use ypipe_t #4691

Closed automanxzq closed 4 months ago

automanxzq commented 4 months ago

Issue description

Consumer threads can never be awakened

Environment

linux,laster version;

Minimal test code / Steps to reproduce the issue

When the producer thread calls the "flush" interface and returns false, then go to "notify"; When the consumer thread calls "checkunread" and returns "false", then go to "wait". However, the order of these two cannot be guaranteed in the implementation of ypipe_t. Because the order of operations for c cannot be guaranteed. It is possible to set "c" to "NULL" in the read thread. At this time, the read thread may fail to reach the "wait" due to scheduling or business time, and the "flush" interface may notify the CAS of the write thread too early. As the read thread has not yet reached the wait, it cannot be awakened. The subsequent flush interface will always return true.