Flush buffers on thread exit