uv_queue_work

312 views
Skip to first unread message

George Spelvin

unread,
Jul 19, 2015, 3:56:51 AM7/19/15
to li...@googlegroups.com
Hi,

I'm new to libuv and I'd like to use libuv's work queue feature in a project. Though I read, that uv_queue_work isn't thread safe and I'm unsure what that exactly means.

I'd like to use the libuv worker thread implementation from several different threads, of course all of them with their own unique event loops. So uv_work_queue() might be called in parallel by different threads. It's this possible? Do I have to serialize probably parallel calls to uv_queue_work (f.e. by mutexes)? Or do I have to implement the whole queue/thread pool stuff in a thread safe manner by my own?

Best regard
George Spelvin

George Spelvin

unread,
Jul 19, 2015, 6:11:31 AM7/19/15
to li...@googlegroups.com
Hi,

I did some experiments now, and I think I understand what thread-safe means. You mean, that the callbacks are not thread-safe, do you? So if there is shared data handled in them, they must be manually synchronized. Thanks.

Saúl Ibarra Corretgé

unread,
Jul 20, 2015, 3:51:15 AM7/20/15
to li...@googlegroups.com
Hi,

uv_queue_work must be called from a thread running an event loop. The
work callback will be called in a thread from the pool, but the after
work callback will be called in the loop thread.

Also note that you cannot call libuv functions such as uv_write from
within the work callback, because they are not thread safe.

Happy looping!


Cheers,

--
Saúl Ibarra Corretgé
bettercallsaghul.com


signature.asc
Reply all
Reply to author
Forward
0 new messages