[Libwebsockets] Execute callback on event loop thread

Ivan Kolesnikov kiv.apple at gmail.com
Sat Jul 24 01:34:58 CEST 2021


Hi,

I have two threads in my application: the first is doing my own stuff and
the second is running a loop with a lws_service call. And sometimes I want
to send some data via WebSocket from the first thread. But WebSockets API
is not thread-safe as I understand, so I want to execute some callback
which will do actual sending on the event loop thread. Like as uv_async_t
in libuv can do that.

Is there any API in libwebsockets which allows it to execute some callback
on event loop thread? Or is there a possibility to obtain a uv_loop_t
instance to use uv_async_t? (I am using libwebsockets with libuv support
enabled).

The another solution came to my mind also - use lws_sul_schedule to
schedule my callback within one microsecond, but it seems to be not
thread-safe too if libwebsockets compiled without SMP support (and SMP
cannot be enabled without pthread library which is not available on Win32
MSVC target which is one of these I am compiling - I am using threading
support from libuv in my program, so I have no dependency on pthread).

Best regards,
Ivan Kolesnikov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210724/0bdc6de7/attachment.htm>


More information about the Libwebsockets mailing list