Page 1 of 1

Can not make graceful exit (C-API) program

Posted: 14 Sep 2018 20:24
by whipped
Hello

I am using z-way libzway API quite successfully in my C application it
seems to be quite robust as is.
However the exit - I cannot make it cleanly.
The app (service) is terminated by a signal SIGINT, SIGHUP or SIGTERM
launcing ShutdownHandler
The ShutdownHandler calls for zway_stop(zway) & zway_terminate(&zway)
but either one is re-calling the ShutdownHandler again and this leads into
endless loop so the service never stops.
I do have several zdata_add_callback_ex() "threads"in the program but trying to cancel/free them
(before zway_stop() in ShutdownHandler) with zdata_remove_callback_ex() does
return something else than 'NoError'
I do have to go throug ShutdownHandler as the other parts of the software needs cleaning also.

Re: Can not make graceful exit (C-API) program

Posted: 15 Sep 2018 21:20
by PoltoS
  • zway_stop is stopping the Z-Way thread (opposite to zway_start)
  • zway_terminate is freeing zway structure (opposite to zway_init) - it calls zway_stop internally before freeing
The termination_callback is called on Z-Way thread stop, so on both cases. But in this callback function you don't need to call zway_stop or zway_terminate - this callback is for you to trap Z-Way thread termination.

Re: Can not make graceful exit (C-API) program

Posted: 17 Sep 2018 16:18
by whipped
Great,
Thanks for pointing the direction - got it now.