1,安装
sudo apt install valgrind
2,代码pthread.c
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER;
void* thread_func1(void* arg) {
pthread_mutex_lock(&lock1);
printf("Thread 1: Locked lock1\n");
sleep(1); // 模拟一些工作
pthread_mutex_lock(&lock2);
printf("Thread 1: Locked lock2\n");
pthread_mutex_unlock(&lock2);
pthread_mutex_unlock(&lock1);
return NULL;
}
void* thread_func2(void* arg) {
pthread_mutex_lock(&lock2);
printf("Thread 2: Locked lock2\n");
sleep(1); // 模拟一些工作
pthread_mutex_lock(
标签:分析,lock,void,valgrind,lock2,死锁,lock1,mutex,pthread
From: https://blog.csdn.net/qq_40008325/article/details/143470967