Browse files

README: Update following 0MQ 2.1.0's thread-safety changes.

  • Loading branch information...
1 parent d859b35 commit 230cb75e605b2a61d468ffdee438be740f13a8da @jeremy-w committed Feb 6, 2011
Showing with 21 additions and 13 deletions.
  1. +21 −13 README.mkd
@@ -25,7 +25,7 @@ for its context.
Thread Safety
-ZeroMQ has some restrictive thread safety and coupling issues:
+Early versions of ZeroMQ had some restrictive thread safety and coupling issues:
* Sockets can only be used from the thread that created them.
* All ZMQ sockets provided in a single call to `zmq_poll()` must have been created using the same context.
@@ -37,26 +37,34 @@ you have to track
each socket's context
and make sure not to mix them.
(The `ZMQSocket` class tracks this for you.)
+This is not as restrictive as it sounds,
+because most applications will only ever use
+a single context.
-Because each socket
-is bound to the thread that created it,
-you must be very careful when using
+Prior to version 2.1.0,
+each socket was permanently bound to the thread that created it.
+This made it very difficult to use
ZeroMQ sockets
with Grand Central Dispatch
-or `NSOperationQueue`.
-The only persistent thread
-that these two expose
+or `NSOperationQueue`, because
+the only persistent thread
+that these two APIs expose
is the thread
you're least likely
to want to perform socket operations on:
the main thread.
+Starting with version 2.1.0,
+a socket can be used from different threads
+provided a full memory barrier,
+such as that introduced by
+`OSMemoryBarrier` function,
+separates the socket's use on one thread
+from its use on another.
To Do
* Add functional tests in the form of sample code.
-* Provide a more (Core)Foundation-like API
-(`CFSocket`, `CFFileDescriptor`)
-that takes advantage of the runloop.
-This is complicated by
-the threading constraints
-present in libzmq-2.0.7.
+* Tie polling into the runloop, similar to
+`NSStream`, `CFSocket`, or `CFFileDescriptor`.

0 comments on commit 230cb75

Please sign in to comment.