I found some callback signature such as data_completion_t, string_completion_t. But I wonder how zookeeper call those functions in asynchronous APIs.
Does it use a single thread to receive response from zookeeper? So I have to add mutex to protect user_data in callback. Or does it check callbacks every time another asyn API has been called?
I tested the C mt library, and found that zookeeper created another 2 threads for IO and completion, the completion function is called in the completion thread, so that those functions should be called sequentially.
the very simple code for the test, the zookeeper server is a standalone listening localhost:3000
Actually, these are explained in the document. http://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html
C Binding
The C binding has a single-threaded and multi-threaded library. The multi-threaded library is easiest to use and is most similar to the Java API. This library will create an IO thread and an event dispatch thread for handling connection maintenance and callbacks. The single-threaded library allows ZooKeeper to be used in event driven applications by exposing the event loop used in the multi-threaded library.