Part of #145349. Requires #145358. Required by #146863. Once the mutex has been implemented, we can register functions to be called for exit with `atexit`.
Part of #145349. Requires #145358. Required by #146863. Once the mutex has been implemented, we can register functions to be called for exit with `atexit`.