Repository: pytorch
Issue: _If pin_memory_thread is alive but dataqueue is empty, it will fall into a dead loop,
Labels: module: dataloader,triaged,module: data

### 🐛 Describe the bug

in torch.utils.data.dataloader.py中
![image](https://github.com/pytorch/pytorch/assets/51702343/b0af7f82-77cd-44b6-a6e1-9ca80bbba3c0)
![image](https://github.com/pytorch/pytorch/assets/51702343/b7f37e26-6f05-4e67-9104-c38c685b5a80)


### Versions

Collecting environment information...
PyTorch version: 1.10.0
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Clang version: 13.0.1
CMake version: version 3.25.1
Libc version: glibc-2.25

Python version: 3.6.9 (default, Nov 25 2022, 14:10:45)  [GCC 8.4.0] (64-bit runtime)
Python platform: Linux-5.4.250-2-velinux1u1-amd64-x86_64-with-Ubuntu-18.04-bionic
Is CUDA available: True
CUDA runtime version: 11.3.109
CUDA_MODULE_LOADING set to: 
GPU models and configuration: 
GPU 0: Tesla V100-SXM2-32GB
GPU 1: Tesla V100-SXM2-32GB
GPU 2: Tesla V100-SXM2-32GB
GPU 3: Tesla V100-SXM2-32GB
GPU 4: Tesla V100-SXM2-32GB
GPU 5: Tesla V100-SXM2-32GB
GPU 6: Tesla V100-SXM2-32GB
GPU 7: Tesla V100-SXM2-32GB

Nvidia driver version: 470.129.06
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.2.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.2.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.2.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.2.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.2.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.2.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.2.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              84
On-line CPU(s) list: 0-83
Thread(s) per core:  2
Core(s) per socket:  21
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               85
Model name:          Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz
Stepping:            7
CPU MHz:             2400.000
BogoMIPS:            4800.00
Hypervisor vendor:   KVM
Virtualization type: full
L1d cache:           32K
L1i cache:           32K
L2 cache:            1024K
L3 cache:            36608K
NUMA node0 CPU(s):   0-41
NUMA node1 CPU(s):   42-83
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat umip pku ospke avx512_vnni md_clear arch_capabilities

Versions of relevant libraries:
[pip3] flake8==5.0.4
[pip3] horizon-plugin-pytorch==100.29.41
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.19.5
[pip3] onnx==1.11.0
[pip3] onnx-graphsurgeon==0.3.20
[pip3] onnx-simplifier==0.3.10
[pip3] onnxoptimizer==0.2.7
[pip3] onnxruntime==1.10.0
[pip3] pytorch-quantization==2.1.2
[pip3] torch==1.10.0
[pip3] torch-cluster==1.5.9
[pip3] torch-geometric==2.0.3
[pip3] torch-scatter==2.0.9
[pip3] torch-sparse==0.6.12
[pip3] torch-spline-conv==1.2.1
[pip3] torch-tb-profiler==0.4.1
[pip3] torchaudio==0.10.0
[pip3] torchvision==0.11.0a0+fa347eb
[conda] Could not collect

cc @andrewkho @gokulavasan @SsnL @VitalyFedyunin @dzhulgakov