Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thread safe channel interface #177

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

darkdragon-001
Copy link

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.

abligh and others added 7 commits March 1, 2016 19:52
This patch provides an experimental zmqchan.ChannelPair class which wraps a
zmq socket (as provided by https://github.com/pebbe/zmq4 ) into a TX and
RX channel.

Currently ZMQ sockets are not threadsafe. These are difficult to use in
combination with golang channels as you can poll on a set of sockets, or
select on a set of channels, but not both. This creates problems if you
want to use conventional go techniques, e.g. using a chan bool for ending
goroutines.

This experimental library provides a means of wrapping a ZMQ socket into
a ChannelPair, which provides an Rx and Tx channel (as well as an error
channel). This is loosely based on the idea of another go binding:
   http://github.com/vaughan0/go-zmq
but works with ZMQ 4.x.

This is currently lightly tested / experimental.

Signed-off-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Alex Bligh <alex@alex.org.uk>
Signed-off-by: Alex Bligh <alex@alex.org.uk>
@darkdragon-001
Copy link
Author

@pebbe Could you have a look?

@doctordesh
Copy link

doctordesh commented Aug 18, 2022

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
Copy link
Author

darkdragon-001 commented Oct 3, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants