pebbe / zmq4

A Go interface to ZeroMQ version 4
BSD 2-Clause "Simplified" License
1.17k stars 166 forks source link

Add thread safe channel interface #177

Open darkdragon-001 opened 2 years ago

darkdragon-001 commented 2 years ago

In order to use zmq the go way, this PR adds a thread safe channel interface provided by abligh/zmqchan. Permission is granted by the author in abligh/zmqchan#1.

darkdragon-001 commented 2 years ago

@pebbe Could you have a look?

doctordesh commented 2 years ago

The intention is not to be pessimistic, but wouldn't this work better as a utility library instead of built into the pebbe/zmq4? No one wants to use Socket non-thread safe (because it leads to nasty bugs) so then we should re-design the current socket if thread-safety is the goal instead of providing an alternative use case.

darkdragon-001 commented 1 year ago

@doctordesh Adding thread safety to such an interface would probably mean synchronizing all over the place (mutex, semaphore, ...) which I imagine to degrade the speed. That's why go invented channels in order to combine thread safety and speed at the same time. The ZMQ C sockets are not meant to be used from multiple threads at the same time.

The advantage of having this in pebbe/zmq4 instead of being a separate library is that it is being made sure that it stays compatible when interfaces change.