On Mon, 2018-12-31 at 09:15 +0530, anand n wrote: > Team, > > I am building a multi threaded application in linux with C as the > programming language and use ZMQ_PAIR sockets for inter-thread > communication (zmq version - 4.3.0). The main thread of the > application > communicates with external applications using router-dealer model. > > The application process spawns multiple child threads for handling > specific > functionalities. Each thread creates two ZMQ_PAIR sockets (one for > bind & > the other for connect) and bind & connect these sockets to same end > point > (inproc://<unique-name-per-thread>). All these are done during > process > initialization and finally the threads invoke zmq_poll on the bind > socket. > The connect socket is only used for sending messages to the thread > and the > bind socket is used to receive them. > > The thread publishes APIs to other threads and messages are sent to > the > connect socket of the thread from these APIs (in non-blocking mode). > Of > course socket access (i.e, zmq_send) is mutex protected from > application > perspective. > > I've tested the application and its working fine so far without any > issues. > I understand that zmq socket is not thread safe and as you see, in > this > model, messages are sent to the connect socket from multiple threads > (not > concurrently anyway due to the mutex protection!). Do you think that > sharing the socket in this way can cause any problem from zmq > perspective? > > Please let me know if something is not clear or if you need more > info. > Thanks a lot for your help. > > Regards, > Anand.
Hi, Sockets are not thread safe, and while things might appear to work fine at first when testing, they might break in subtle ways at any point, so it's discouraged to do that. Note that the setup you are implementing sounds like more or less a re- implementation of the actor model provided by CZMQ. I would strongly encourage you to have a look at CZMQ and at the zactor class - it seems to me it provides what you are looking for: https://github.com/zeromq/czmq#zactor---simple-actor-framework https://github.com/zeromq/czmq#czmq-actors The zactor library APIs are used in production in many places (including where I work) and are well battle-tested. -- Kind regards, Luca Boccassi
signature.asc
Description: This is a digitally signed message part
_______________________________________________ zeromq-dev mailing list [email protected] https://lists.zeromq.org/mailman/listinfo/zeromq-dev
