Make world termination idempotent and thread-safe

When world was terminated twice, the second time the future was not
resolved. This might happen, when calling the termination from more
places (for example in at_exit and trap("SIGINT")).

I've made the call also thread safe, just for sure.