Ilja, There's more detail of Martin's elegant lock-free design here: http://www.zeromq.org/whitepapers:y-suite
-Pieter On Tue, Sep 7, 2010 at 1:12 PM, Martin Sustrik <[email protected]> wrote: > > Hi Ilja, > > You've hit the hairy portion of the codebase :) > >>Trying to understand how 0mq works I am not sure I properly got how >>multithreading is handled. >> >>For example in yqueue_t::push I can see >>== >>if (++end_pos != N) >>== >>though I did not find any attempt to ensure (e.g. by means of memory barriers >>or volatile keyword) >>this variable, modified by multiple threads, is somehow protected. > > The yqueue_t object manages only begin and end points of the queue. End > belongs exclusively to the writer thread, begin belongs exclusively to > the reader thread. Thus there's no synchronisation problem and no > locking or memory barriers are needed. > > As for the elements in the list, these are managed by the object using > yqueue_t, namely ypipe_t. The pipe reader reads the elements that are > already on the read side of the thread border. Once it finds out there > are no more elements available it moves all the elements on the writer > side of the border to the reader side (single atomic operation on a > single pointer) and executes the memory barrier. > > Hope that helps. > Martin > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > > -- - Pieter Hintjens iMatix - www.imatix.com _______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
