orthecreedence / cl-async

Asynchronous IO library for Common Lisp.
MIT License
273 stars 40 forks source link

Can AC:EXIT-EVENT-LOOP be called from any thread? #159

Closed lukego closed 6 years ago

lukego commented 6 years ago

I am not sure from the documentation whether AC:EXIT-EVENT-LOOP can be called from any thread or whether it has to be called from within the event loop?

I am assuming that it has to be called from within the event loop because I don't see any obvious synchronization code to prevent a race condition leading to double-free. If it can indeed be safely called from any thread that would be handy to know though because then I could simplify my shutdown code.

orthecreedence commented 6 years ago

I think because it's mainly just a thin wrapper around libuv's uv_loop_close/uv_stop, and libuv is only threadsafe when using notifiers, I'd guess that it's not safe to call from another thread.

In this case, I'd check out https://orthecreedence.github.io/cl-async/notifiers. It's an extra step, but won't give you segfaults at random times =].

lukego commented 6 years ago

Thanks! Yes that's the approach that I'm taking. It's working out very neatly to push work onto the event loop using mailboxes and notifiers. 👍