c# - NetMq sockets are thread safe? -
i use private field (pushsocket
- zmq_push socket netmq)
private pushsocket _pushsocket;
and 2 methods use socket in different threads
public void method1() { //.....// _pushsocket.sendframe(....); //.....// } public void method2() { //.....// _pushsocket.sendframe(....); //.....// }
should use lock
or synchronization primitives?
no,
on basis of understaning zeromq
prefessional-level recommendation no.1:
one shall not design code sharing sockets among threads.
by design,
zeromq
scaleable formal communication patterns ( a.k.a. bit misleadingly nicknamed socket(s) )
are not thread-safe ( , never tried ).
it not thing of belief in one's capabilities somehow mediate inter-thread signalling, principal belief, scaleable parallel code shall never share, nor block.
thus said zeromq
evangelism.
confused? np.
angry? np.
zero-sharing, zero-locking -- try consider form of collision avoidance, rather having sieve ashes burnt thrashes of uncontrolled concurrent havoc.
if in doubts
one has best option, read pieter hintjens' book "code connected. volume 1" , spend time pieters views on scaleable code design principles.
you fall in love new style of thinking zeromq
-way.
Comments
Post a Comment