Implement automatic termination of glfw in spawn function