Scheduler event timer

22 views
Skip to first unread message

Alex Koch

unread,
Jul 24, 2014, 3:09:28 PM7/24/14
to nx...@googlegroups.com
Hi Yaroslav,

I would like to add a timer to execute a func each X. How can I achieve this in nxweb without blocking? Does the event loop expose such attributes like libev "ev_timer_init()" .

I see something like  nxe_set_timer in nxweb code but I am not 100% sure this is the righ way.

Could you advise?

Thanks,

Alex

Yaroslav

unread,
Jul 24, 2014, 3:49:44 PM7/24/14
to nx...@googlegroups.com
Hi Alex,

nxweb's event loop timers are complicated and not so flexible as in libev.

The easiest way to accomplish your task is to launch your own thread (simply with pthread_create) that will execute your function and sleep for the time interval. I presume your function is going to modify some shared data. Make sure you use a mutex to avoid concurrecy problems. You will need mutex even when using event timers as there are several network threads anyway.

You can launch the thread in on_server_startup callback of your module. Make sure it is daemon thread so it will not affect server shutdown.

Yaroslav


--
You received this message because you are subscribed to the Google Groups "nxweb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nxweb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages