[zeromq-dev] "thread safe" sockets and ZMQ_FD

Doron Somech somdoron at gmail.com
Sat Feb 21 21:12:04 CET 2015


You are right. I will change it to use scoped lock.

On Sat, Feb 21, 2015 at 6:36 PM, Bjorn Reese <breese at mail1.stofanet.dk>
wrote:

> On 02/21/2015 04:44 PM, Doron Somech wrote:
>
> > (https://github.com/zeromq/libzmq/blob/master/src/mailbox_safe.hpp) have
>
> I had a quick look at this class...
>
> The workaround in the destructor is not thread-safe. Another thread
> may enter and wait between the sync->unlock() and the end of the
> destructor scope. You need to add a state variable to prevent this
> from happening.
>
> Furthermore, if another thread is waiting on the condition variable,
> then the mutex is unlocked while it is waiting. You need to
> notify (broadcast) the condition variable to wake up the other thread
> and get it out of the class. You will most likely need to to add a
> reference count to keep track of how many pending threads are waiting
> in order to know when it is safe to exit the destructor.
>
> The use of sync->lock() and sync->unlock() is not exception safe. I
> suggest that you use a scoped lock instead of the explicit calls. Read
> this for inspiration:
>
>    http://en.cppreference.com/w/cpp/thread/unique_lock
>
> The code does not handle spurious wakeups from the condition variable.
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150221/94d6beaf/attachment.htm>


More information about the zeromq-dev mailing list