Hi all,<div><br></div><div>I&#39;m debugging an issue with multithreading and FFI calls in 7.4.1. The code in question is the zeromq3-haskell library, which provides an FFI binding to ZeroMQ.</div><div><br></div><div>A little background: ZeroMQ gives the programmer &quot;contexts&quot; and &quot;sockets&quot;. Contexts are thread-safe and generally used one-per-process, but sockets and not thread-safe so they&#39;re generally used one-per-thread.</div>

<div><br></div><div>Have a look at the code in this gist: <a href="https://gist.github.com/1829190">https://gist.github.com/1829190</a> It&#39;s just a server that prints requests and replies with &quot;Hello&quot;, and a client that sends the requests [&quot;1&quot;, &quot;2&quot;, ..., &quot;10&quot;] and prints the responses.</div>

<div><br></div><div>Despite the fact that ZMQ sockets are not thread-safe, it was possible to compile and run this code with -threaded under 7.0.4. Using MVars or some other locking mechanism, it was even possible to use the same socket from multiple parallel threads. (As long as the socket was not actually used in parallel by multiple threads, all was well.) In 7.4.1, the code will only run if compiled without -threaded. With -threaded, it croaks with an &quot;operation on non-socket&quot; error, which generally refers to a socket that&#39;s either been closed or </div>

<div><br></div><div>I&#39;ve dug through the code in zeromq3-haskell and haven&#39;t found anything suspicious looking. Before I go digging into libzmq itself, can somebody assure me that nothing has changed in 7.4.1 with regard to -threaded or the FFI that might cause this breakage?</div>

<div><br></div><div>Cheers,</div><div>Mike Craig<br><br>
</div>