Closed jimpo closed 1 year ago
Actually, on further investigation, it seems like all the channel constructions that could be used to actually transfer ownership between threads do the memory barrier required by ZMQ.
Any additional thoughts on this? I was about to start using a Socket
without a mutex but then saw this issue.
You second link suggests that there is a thread safe socket type. Does rust-zmq
not use those?
Yeah, my assessment is that it is safe to transfer ownership of Socket
through a channel or a std::thread::spawn
call because those calls do the appropriate memory fence operations. I am closing this issue.
According to the ZMQ API docs
On the page for zmq_socket, the docs say
In the Rust bindings, however,
zmq::Socket
implementsSend
, indicating to the type checker that it is safe to migrate sockets between threads freely. It seems to me thatSocket
should be!Send
. To allow migration between threads, aSocket
could be wrapped in some sort of envelope type to be safely sent between threads which does the memory fence before unwrapping back into aSocket.