Search code examples
zeromqnetmqlate-join

What is the NetMQ equivalent of zthread_fork?


I want to implement an Out-of-Band-Snapshot using NetMQ. zeroMQ (ØMQ) describes this concept in "Chapter 5 - Advanced Pub-Sub Patterns" in the section "Getting-an-Out-of-Band-Snapshot". There are also examples of a server realizing this pattern in C and Java.

What is the NetMQ equivalent for C's zthread_fork() function or Java's ZThread.fork() method?


Solution

  • zthread_fork is the portable API of CZMQ to creating threads. Also zthread is obsolete and czmq now encourage zactor.

    Anyway NetMQ has NetMQActor which is port of zactor.

    To just use zthread_fork you can create a pair of pair socket, give one end to the thread and you have zthread_fork. Something like this:

    var pipe = context.CreatePairSocket();
    pipe.Bind("inproc://socket-pair");
    
    var threadPipe = context.CreatePairSocket();
    threadPipe.Connect("inproc://socket-pair");
    
    Thread thread = new Thread(Run);
    thread.Start(threadPipe);