Perhaps uv_callback would be an option.
With it, we can call functions for other threads.
It can handle non-coalescing calls.
We can even get the result in the caller thread on another function asynchronously. eg:
In the called thread:
uv_callback_t send_data; void * on_data(uv_callback_t *handle, void *data) { int result = do_something(data); free(data); return (void*)result; } uv_callback_init(loop, &send_data, on_data, UV_DEFAULT);
In the calling thread:
uv_callback_t result_cb; void * on_result(uv_callback_t *handle, void *result) { printf("The result is %d\n", (int)result); } uv_callback_init(loop, &result_cb, on_result, UV_DEFAULT); uv_callback_fire(&send_data, data, &result_cb);
source share