The 40465600 reversion did not setup the atomic loop to set the cancel bits correctly. The fix is essentially what pthread_cancel did prior 26cfbb71. Checked on x86_64-linux-gnu and aarch64-linux-gnu. (cherry picked from commit 62be9681)