[zeromq-dev] Socket connect status

Martin Sustrik sustrik at 250bpm.com
Wed Mar 17 14:53:24 CET 2010


Diablo 666 wrote:
> Hi,
> 
>  > Ok. Fair enough. I believe more people are struggling with the same
>  > problem. What about writing a simple sync API implementation?
> 
> for my use case, it would be sufficient to check if the underlying queue
> is empty. This should be very easy to implement by simply checking if
> begin_pos == end_pos in yqueue_t and calling this method via the
> socket. This would prevent any use of synchronizing. Do you see any
> drawback within this approach?

The problem is that each end of the queue lives in a different thread. 
Writer thread cannot access read end of the queue and vice versa. Note 
that there's no mutex that would lock the whole queue and let you check 
whether it's empty. It's a lock-free queue (synchronisation between the 
threads is done using CPU's atomic operations and memory barriers).

Martin



More information about the zeromq-dev mailing list