flush must be synchronized