-
|
I have a multithreaded application where I have several worker threads and a different thread running the uv_loop. I am writing back to the loop using an async_send cb. However, when I do it that way the uv_write_cb doesn't get called immediately, but it seems to be called the next time some other event callback happens on the loop. On the example below, 'on_write_end' is not called but until there is some other event on the loop. void async_write(uv_async_t* async) {
response_data_t *response_data = async->data;
uv_stream_t *client = response_data->client;
client_request_data *client_data = client->data;
int* buffer = response_data->buffer;
size_t size = response_data->size;
uv_buf_t wrbuf = uv_buf_init((char*)buffer,size);
uv_write_t* write_req = response_data->write_req;
write_req->data = (void*)client_data->client;
uv_write(write_req,client,&wrbuf,1,on_write_end);
client_data->ready_to_write = 1;
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
|
No, that's not expected. 9 out of 10 times it's some kind of thread safety issue in the program but your snippet doesn't provide enough context for me to guess what. NB: I'm assuming that "immediately" doesn't mean you expect on_write_end to have been called by the time uv_write() returns. |
Beta Was this translation helpful? Give feedback.
I must admit that I am a bit ashamed of the source of the issue, but all seemed to came down for me not calling async events using uv_async_send() mechanism.
@saghul, yes I've used them and like them very much. I am using this for a producer-consumer model for my MSc thesis and therefore wanted more control on instantiation of threads.