On 28/06/2012, at 08:22, Jeroen Janssen wrote: > On Jun 28, 1:18 am, Ben Noordhuis <i...@bnoordhuis.nl> wrote: >>>> No. What pattern do you use? Something like this? >> >>>> if (!ev_async_pending(w)) >>>> ev_async_send(w); >> >>> Ben, I think this should just be the default behaviour of libuv. >> >> Agreed. Though I still would like to know if that's the actual pattern >> that Jorge uses. :-) > > I think you can see the relevant code at > https://github.com/xk/node-threads-a-gogo/blob/master/src/threads_a_gogo.cc
Yes, here: https://github.com/xk/node-threads-a-gogo/blob/master/src/threads_a_gogo.cc#L202 https://github.com/xk/node-threads-a-gogo/blob/master/src/threads_a_gogo.cc#L281 https://github.com/xk/node-threads-a-gogo/blob/master/src/threads_a_gogo.cc#L646 https://github.com/xk/node-sound/blob/master/src/sound.cc#L509 https://github.com/xk/node-sound/blob/master/src/sound.cc#L1014 But ev_async_pending is a macro that expands to this: if (!(+(&watcher)->sent)) ev_async_send(ev_default_loop_uc_ (), &watcher); which is not a function call, soooo.... it's not a good idea to make it "the default behaviour", because if you do that the check would be made inside uv_async_send() so the function call would happen always which is exactly what one's trying to avoid when using ev_async_pending. -- Jorge.