On Tue, Dec 29, 2015 at 12:34 AM, Darren Smith <[email protected]> wrote: > Thanks for quick answer Ben. > > Yes, this looks like exactly what I need. uv_async_send -- Wakeup the event > loop and call the async handle’s callback. > > Regarding callback coalescing, I think it shouldn't be an issue since I'll > use a mutex & message queue, and I'll call uv_async_send only after the > message queue has been prepared. So I don't think the following has a race > condition: > > static uv_async_t async; > > // concurrently called by many worker threads, & inc. UV Loop thread. > void push_event(Event evt) > { > { > unique_lock<mutex> guard( queue_mutex ); > my_queue.push_back( evt ); > } > uv_async_send( &async ); > } > > > // called by UV Loop > void async_cb(uv_async_t* handle) > { > vector<Event> new_events; > { > unique_lock<mutex> guard( queue_mutex ); > new_events.swap( my_queue ); > } > > // ... for each Event in new_events, do uv_tcp_init & uv_tcp_connect > }
Yes, that should work. The key is to clear the whole queue instead of popping just the first element. -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
