Fix segmentation fault due to access to destroyed CudaIPCGlobalEntities instance (#56141)
Summary:
There is an instance of the static destruction order fiasco where cuda_ipc_global_entities may be accessed after it is destroyed. See https://github.com/pytorch/pytorch/issues/51961
This change uses a flag and avoids accesses to the destroyed class when it is set to false.
Fixes https://github.com/pytorch/pytorch/issues/51961
This removes the function to clear shared_blocks introduced by https://github.com/pytorch/pytorch/issues/53080 which had multiple issues: Unprotected access to a shared structure and modification of the vector which is being cleared by the destructors of the objects contained.
I.e. what happened was:
- `CudaIPCSentDataLimbo_.clear_shared_blocks();` is called from the destructor of CudaIPCGlobalEntities as of your PR
- This deletes instances of `CudaIPCSentData` which hold `at::DataPtr` created by `GetNewRefCountedSentData`
- This means `CudaIPCSentDataDelete` is called with still active pointers
- Hence `CudaIPCSentDataLimbo_.add` is called adding a new value to `shared_blocks_`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56141
Reviewed By: ejguan
Differential Revision: D30397279
Pulled By: VitalyFedyunin
fbshipit-source-id: ce4b8b90fa1c90d275e5eca93ba84321cbc6140a