Communication from EventLoop thread to process's main thread #738
-
I am writing a process that uses libuv as the main event loop. It handles various events asynchronously, including events from the AWS IOT Device SDK for CPP v2. The problem I am facing is that the main event loop runs in the default thread, while the callbacks from the SDK (e.g. the one set with WithClientConnectionSuccessCallback()) run in a separate thread. I would like to be able to pass data from the callback to the main thread, but I don't know of a thread-safe way to do it. Of course, this situation is not unique to me, so I would like to know what is the suggested way to achieve this. TIA! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The simplest way is to just use a (1) lock/mutex for data protection and (2) signal/condition variable for notifications. Using libuv though, there may be a way to tie into its API directly and replace (2) with a signal to whatever edge-trigger system that libuv likely uses (epoll/kqueue/iocp etc...). |
Beta Was this translation helpful? Give feedback.
The simplest way is to just use a (1) lock/mutex for data protection and (2) signal/condition variable for notifications.
Using libuv though, there may be a way to tie into its API directly and replace (2) with a signal to whatever edge-trigger system that libuv likely uses (epoll/kqueue/iocp etc...).