[zeromq-dev] exception thrown on socket recieve function call in c# interop bindings
johnny at jgoz.net
Sat Feb 11 00:05:18 CET 2012
> I think I just found a solution to this. Had to put a pause right before
Well, I wouldn't call that a "solution", per se. It's probably just masking
the real problem.
After digging into the codebase for the Interop bindings, I think your
problem might be the bindings themselves.
It looks like the ZmqSocket class keeps a static list of all instantiated
sockets. It then has a background thread that iterates over them, calling
zmq_poll on each socket individually, firing any OnReceive events as
appropriate. The scheduler thread locks the entire socket list while it is
polling, but it doesn't prevent multiple threads from accessing individual
sockets at the same time.
Aside from completely defeating the purpose of zmq_poll, this is a major
problem because zmq sockets are not thread-safe. It's also a really shoddy
example of multi-threaded programming, in C# or in any language.
My recommendation to you would be to convert your program to use the latest
stable version (2.2.x) of the official clrzmq bindings. These come bundled
with libzmq 2.1.11. You can install them via NuGet (clrzmq package) or
download them from GitHub.
More info here: https://github.com/zeromq/clrzmq/tree/2.2
At the very least, it will help you isolate the problem.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the zeromq-dev