TS-2624: Make thread affinity more robust