On Mon, 2017-04-24 at 19:17 -0700, Narsilx Liao wrote: > > > Ben Noordhuis於 2017年4月25日星期二 UTC+8上午5時23分05秒寫道: > > On Mon, Apr 24, 2017 at 12:54 PM, Narsilx Liao <[email protected]> > > wrote: > > > Hi everyone, > > > > > > I'm new to libuv and I know that is not thread-safe except > > > uv_async_send(). > > > > > > I'm writing a program(with linux c) that will create a thread(the > > loop > > > thread) for uv_run(), which receives commands from a socket fd > > for creating > > > or removing timers from the same loop.The Main thread will send > > commands > > > through another socket fd to control timers creating/removing on > > the loop. > > > > > > I wonder that is it safe to add a new timer to a loop in a > > uv_poll_t > > > callback which also on the same loop? > > > > Yes, that is safe. > > > > > in the callback should I call uv_stop() the loop first , add a > > new timer to > > > loop and uv_run() the loop again?or It is safe to add a timer > > directly > > > without uv_stop() and uv_run() the loop? > > > > I assume uv_stop() means uv_poll_stop()? Not necessary, you can > > create the timer handle immediately. > > > Oh, I mean, should I stop the current loop with > uv_stop(uv_loop_t* loop) first, and create timers with the loop, > then uv_run() the loop again?or just init and start timers without > uv_stop(loop) and uv_start(loop, mode)? >
If you are in the loop thread you can create and start timers at any point. Doing it from another handle's callback is fine. > > -- > 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. -- 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.
