make flushing thread safe