Fix race condition in wakeupThreadOnCapability() (#2574)