[zeromq-dev] Should I replace mutex using ZMQ?

Steve Murphy murf at parsetree.com
Tue Apr 15 06:38:12 CEST 2014


Mo--

I'm kinda new myself, but I think you on the right track with letting a
separate thread D manage that state info.

Erlang has a really involved messaging mechanism for managing "shared"
memory, including optional acknowledgement when the change is actually
complete, the ability to search for requests in the incoming message pool,
etc. In 0MQ, you could build as fancy or as simple a messaging system as
you need.

Now, just remember that all threads communicating with your D thread  must
share the same zctx, so use the zthread_fork, to make all the threads, and
thereby use the same zctx. (That's what the book says, and it works for me).

murf



On Mon, Apr 14, 2014 at 9:23 PM, Dong Mo <montedong at gmail.com> wrote:

> Dear list,
>
> I am very new to zmq and noticed in
> http://zguide.zeromq.org/page:all#Multithreading-with-MQ that it seems to
> be a good idea to replace mutex with message passing in zmq.
>
> But my question is that how should I exactly transform from the notion of
> mutex, conditional variable and etc to the thinking pattern of zmq.
>
> Here is an example I encountered:
>
> I have thread A, B, C. They will all modify state S. In the past, I will
> do lock on this shared state and they can coordinate, but I don't know how
> to express the mutex semantic using zmq. One way I think of is that I
> create another thread D and let A,B,C communicate with D over zmq when they
> want to manipulate S, and there will be no race condition since D is
> coordinating everything. But I feel that this is definitely not the best
> practice...
>
> So could you inform me what is it and why it is worthwhile to use zmq
> instead of mutex
>
> Sorry if this question is naiive, still trying to figure things out.
>
> Thank you very much
> -Mo
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>


-- 

Steve Murphy
ParseTree Corporation
57 Lane 17
Cody, WY 82414
✉  murf at parsetree dot com
☎ 307-899-5535
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140414/d22094a0/attachment.htm>


More information about the zeromq-dev mailing list