wait output read thread exit after program exits