Parameters: |
|
---|
In general, you cannot use a Loop from multiple threads or other asynchronous sources such as signal handlers (as opposed to multiple event loops - those are of course safe to use in different threads).
Sometimes, however, you need to wake up an event loop you do not control, for example because it belongs to another thread. This is what Async watchers do: as long as the Async watcher is active, you can signal it by calling send(), which is thread- and signal safe.
This functionality is very similar to Signal watchers, as signals, too, are asynchronous in nature, and signals, too, will be compressed (i.e. the number of callback invocations may be less than the number of send() calls). In fact, you could use signal watchers as a kind of ‘global async watchers’ by using a watcher on an otherwise unused signal, and signal this watcher from another thread, even without knowing which loop owns the signal.
Sends/signals/activates the Async watcher, that is, feeds an EV_ASYNC event on the watcher into the event loop, and returns immediately.
Note that, as with other watchers in libev, multiple events might get compressed into a single callback invocation (another way to look at this is that Async watchers are level-triggered, set on send(), reset when the event loop detects that).
This call incurs the overhead of a system call only once per event loop iteration, so while the overhead might be noticeable, it doesn’t apply to repeated calls to send() for the same event loop.