In 多线程the program, 多个线程使用同一个互斥锁时which 一个线程``拿到了互斥锁then, however 一直不释放互斥锁, lead to 其他线程一直阻塞internal locking function, this phenomenon is 死锁a phenomenon
In the 多线程program, there 两个互斥锁are mutex lock A and mutex lock B respectively in the program. The program is running, 线程1got it 互斥锁A, 线程Bgot it 互斥锁B, the 都不释放respective mutex locks of thread 1 and thread 2 , and also want to apply for them 拿对方的互斥锁. 都阻塞This phenomenon is also a 死锁phenomenon when the thread is inside the function holding each other's mutex lock
2. Simulate deadlock program
Thread 1 gets the mutex lock A and never releases the mutex lock A
Thread 2 gets the mutex lock B and never releases the mutex lock B
Thread 1 applies for mutex lock B
Thread 2 applies for mutex lock A
Both threads are 阻塞in lock_wait in the pthread_mutex_lock function