title: inter thread comunication using ZeroMQ messages
body: <p>I am trying to use <code>zeroMQ</code> as a way to implement a messaging system between multiple threads. I tried the code below but it doesn't work; in the specific the call to <code>zmq_recv</code> in each thread doesn't wait/block for any message to be executed.</p>
  
  <p>Can you help me with this piece of code?</p>
  
  <p>I am using Linux OS and gcc</p>
  
  <p>Best Regards</p>
  
  <p>AFG</p>
  
  <pre><code>    static void *
      worker_routine (void *context) {
          // Socket to talk to dispatcher
          void *receiver = zmq_socket (context, ZMQ_REP);
          zmq_connect (receiver, "inproc://workers");
          while (1) {
  
              zmq_msg_t request;
              zmq_msg_init( &amp;request );
              zmq_recv( receiver, &amp;request, 0 );
              printf ("Received request\n");
              // Do some 'work'
              usleep (1000);
              // Send reply back to client
              zmq_send (receiver, &amp;request, 0);
          }
          zmq_close (receiver);
          return NULL;
      }
  
      int main (void) {
  
      void *context = zmq_init (1);
      void *clients = zmq_socket (context, ZMQ_REP);
      zmq_bind (clients, "inproc://workers");
  
      int thread_nbr;
      for (thread_nbr = 0; thread_nbr &lt; 5; thread_nbr++) {
          pthread_t worker;
          pthread_create (&amp;worker, NULL, worker_routine, context);
      }
  
      zmq_close (clients);
      zmq_term (context);
      return 0;
      }
  </code></pre>