Am 16.11.2017 um 09:56 schrieb Alexey Kulentsov:
On Sun, 12 Nov 2017 20:44:54 +0100, Christian Köstlin wrote:
Hi,
I have an application, that uses vibe as an embedded webserver, but at
the same time does some traditional spawn/spawnLinked work.
I am having problems shutting down the system in a controlled manner.
e.g. vibe catches ctrl-c and shuts down the eventloop, but how can I add
to this hook, to shutdown my own thread?
I found some old newsgroup posts that seemed to use module initializer,
perhaps you could go into more detail?Thanks in advance,
ChristianFrom my application:
app.dshared static ~this() // called on exit { import core.memory; if(webInterface !is null) webInterface.destruct(); // call destruction routine GC.collect(); // reduce noice in Valgrind report GC.minimize();// omit if you don't use it }
In the destruction routine, I send exit message to each background task and wait until they exit, something like this:
myTask.send(ExitMessage()); myTask.join;
To add to this, it is also possible to disable vibe.d's signal handlers
completely using disableDefaultSignalHandlers()
, and to install a
custom routine using the method of choice to handle the shutdown
(eventcore provides event loop based signal handling, which would be the
simplest solution if vibe-core is being used).