atomic writing of return code