-
Notifications
You must be signed in to change notification settings - Fork 163
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
base: master
Are you sure you want to change the base?
Conversation
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>
@pebbe Could you have a look? |
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 |
@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 |
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.