Fix a segfault in DeviceThreadHandlePool and PoolWindow (#36416)
Summary:
This PR fixes a bug related to object destruction order across threads. The bug can cause segfaults during shutdown of processes that use libtorch.
See https://github.com/pytorch/pytorch/issues/36408 for more detail
Pull Request resolved: https://github.com/pytorch/pytorch/pull/36416
Differential Revision: D21006321
Pulled By: ezyang
fbshipit-source-id: da97936d9f2ed3f3e3aba8a3a29b38314f04b57f