Implement _ThreadWaiter and switch retry-related things to use it. This has not yet been tested.

_PipeWaiter will come soon.