【Linux C | 多线程编程】线程同步 | 条件变量 的 使用总结

😁博客主页😁:🚀https://blog.csdn.net/wkd_007🚀
🤑博客内容🤑:🍭嵌入式开发、Linux、C语言、C++、数据结构、音视频🍭
⏰发布时间⏰:2024-04-15 21:17:44

本文未经允许,不得转发!!!


相关文章:
【Linux C | 多线程编程】线程同步 | 互斥量(互斥锁)介绍和使用
【Linux C | 多线程编程】线程同步 | 条件变量(万字详解)
【Linux C | 多线程编程】线程同步 | 条件变量 的 使用总结


在这里插入图片描述

🎄一、概述

上篇文章介绍了条件变量,可以学会怎样使用,但有些问题介绍的比较分散,本文主要是做个补充,从下面几个问题进行展开,你也可以先看看是否可以知道答案。
1、为什么需要条件变量?
2、pthread_cond_wait 函数做了什么操作?
3、条件变量为什么需要和互斥量一起使用?
4、既然互斥量和条件变量关系如此紧密,为什么不干脆将互斥量变成条件变量的一部分呢?
5、互斥量加锁的临界区应该包含哪些操作?
6、为什么条件等待时,使用while来判断条件,而不是用if ?

while(list_empty(&productList)) // 条件不满足
{
	pthread_cond_wait(&product_cond, &product_mutex);
}

7、先唤醒后解锁,还是先解锁后唤醒?


本文的某些问题会给出示例代码,下面是一个是会用的头文件linux_list.h,它是Linux内核使用的一个链表。需要了解使用方法的,可以看这文章【数据结构】list.h 详细使用教程
先在这里给出:

// my_list.h 2023-09-24 23:07:43
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H

struct list_head {
	struct list_head *next, *prev;
};


#define INIT_LIST_HEAD(ptr) do { \
	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)

/**
 * list_empty - tests whether a list is empty
 * @head: the list to test.
 */
static inline int list_empty(const struct list_head *head)
{
	return head->next == head;
}

/*
 * Insert a new entry between two known consecutive entries.
 *
 * This is only for internal list manipulation where we know
 * the prev/next entries already!
 */
static inline void __list_add(struct list_head *new_node,
		struct list_head *prev,
		struct list_head *next)
{
	next->prev = new_node;
	new_node->next = next;
	new_node->prev = prev;
	prev->next = new_node;
}

/**
 * list_add - add a new entry
 * @new: new entry to be added
 * @head: list head to add it after
 *
 * Insert a new entry after the specified head.
 * This is good for implementing stacks.
 */
static inline void list_add(struct list_head *new_node, struct list_head *head)
{
	__list_add(new_node, head, head->next);
}

/**
 * list_add_tail - add a new entry
 * @new: new entry to be added
 * @head: list head to add it before
 *
 * Insert a new entry before the specified head.
 * This is useful for implementing queues.
 */
static inline void list_add_tail(struct list_head *new_node, struct list_head *head)
{
	__list_add(new_node, head->prev, head);
}

/*
 * Delete a list entry by making the prev/next entries
 * point to each other.
 *
 * This is only for internal list manipulation where we know
 * the prev/next entries already!
 */
static inline void __list_del(struct list_head * prev, struct list_head * next)
{
	next->prev = prev;
	prev->next = next;
}

/**
 * list_del - deletes entry from list.
 * @entry: the element to delete from the list.
 * Note: list_empty on entry does not return true after this, the entry is
 * in an undefined state.
 */
static inline void list_del(struct list_head *entry)
{
	__list_del(entry->prev, entry->next);
	//entry->next = (struct list_head *)LIST_POISON1;
	//entry->prev = (struct list_head *)LIST_POISON2;
}

#ifndef offsetof
#define offsetof(type, f) ((size_t) \
		((char *)&((type *)0)->f - (char *)(type *)0))
#endif

#ifndef container_of
#define container_of(ptr, type, member) ({ \
		const typeof( ((type *)0)->member ) *__mptr = (ptr);\
		(type *)( (char *)__mptr - offsetof(type,member) );})
#endif

/**
 * list_entry - get the struct for this entry
 * @ptr:	the &struct list_head pointer.
 * @type:	the type of the struct this is embedded in.
 * @member:	the name of the list_struct within the struct.
 */
#define list_entry(ptr, type, member) \
	container_of(ptr, type, member)

#ifndef ARCH_HAS_PREFETCH
static inline void prefetch(const void *x) {;}
#endif

/**
 * list_for_each	-	iterate over a list
 * @pos:	the &struct list_head to use as a loop counter.
 * @head:	the head for your list.
 */
#define list_for_each(pos, head) \
	for (pos = (head)->next; prefetch(pos->next), pos != (head); \
			pos = pos->next)

/**
 * list_for_each_safe	-	iterate over a list safe against removal of list entry
 * @pos:	the &struct list_head to use as a loop counter.
 * @n:		another &struct list_head to use as temporary storage
 * @head:	the head for your list.
 */
#define list_for_each_safe(pos, n, head) \
	for (pos = (head)->next, n = pos->next; pos != (head); \
			pos = n, n = pos->next)
			
/**
 * list_for_each_entry	-	iterate over list of given type
 * @pos:	the type * to use as a loop counter.
 * @head:	the head for your list.
 * @member:	the name of the list_struct within the struct.
 */
#define list_for_each_entry(pos, head, member)				\
	for (pos = list_entry((head)->next, typeof(*pos), member);	\
			prefetch(pos->member.next), &pos->member != (head); 	\
			pos = list_entry(pos->member.next, typeof(*pos), member))


#endif //_LINUX_LIST_H

在这里插入图片描述

🎄二、条件变量相关思考

✨2.1 为什么需要条件变量?

参考答案:
因为如果不使用条件变量,线程就需要 轮询+休眠 来查看是否满足条件,这样严重影响效率。

下面是不使用条件变量的代码,th_consumer线程需要轮询查看是否有数据(条件是否满足),并且需要通过sleep函数休眠来释放CPU给其他线程:

// 09_producer_consumer.c
// gcc 09_producer_consumer.c -lpthread
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "linux_list.h"

#define  COMSUMER_NUM	2

typedef struct _product
{
	struct list_head list_node;
	int product_id;
}product_t;

struct list_head productList;// 头结点
pthread_mutex_t product_mutex = PTHREAD_MUTEX_INITIALIZER;	// productList 的互斥量

// 生产者线程,1秒生成一个产品放到链表
void *th_producer(void *arg)
{
	int id = 0;
	while(1)
	{
		product_t *pProduct = (product_t*)malloc(sizeof(product_t));
		pProduct->product_id = id++;
		
		pthread_mutex_lock(&product_mutex);
		list_add_tail(&pProduct->list_node, &productList);
		pthread_mutex_unlock(&product_mutex);
		
		sleep(1);
	}
	
	return NULL;
}

// 消费者线程,1秒消耗掉一个产品
void *th_consumer(void *arg)
{
	while(1)
	{
		pthread_mutex_lock(&product_mutex);
		if(!list_empty(&productList)) // 不为空,则取出一个
		{
			product_t* pProduct = list_entry(productList.next, product_t, list_node);// 获取第一个节点
			printf("consumer[%d] get product id=%d\n", *((int*)arg), pProduct->product_id);
			list_del(productList.next); // 删除第一个节点
			free(pProduct);
		}
		pthread_mutex_unlock(&product_mutex);
		sleep(1);
	}
	return NULL;
}

int main()
{
	INIT_LIST_HEAD(&productList);	// 初始化链表
	
	// 创建生产者线程
	pthread_t producer_thid;
	pthread_create(&producer_thid, NULL, th_producer, NULL);
	
	// 创建消费者线程
	pthread_t consumer_thid[COMSUMER_NUM];
	int i=0, num[COMSUMER_NUM]={0,};
	for(i=0; i<COMSUMER_NUM; i++)
	{
		num[i] = i;
		pthread_create(&consumer_thid[i], NULL, th_consumer, &num[i]);
	}
	
	// 等待线程
	pthread_join(producer_thid, NULL);
	for(i=0; i<COMSUMER_NUM; i++)
	{
		pthread_join(consumer_thid[i], NULL);
	}
	return 0;
}

下面是使用了条件变量的代码,不需要sleep函数去等待,条件不满足时,会阻塞在条件等待函数pthread_cond_wait上,等条件满足时,其他线程会唤醒这个阻塞的线程。

// 09_producer_consumer_cond.c
// gcc 09_producer_consumer_cond.c -lpthread
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include "linux_list.h"

#define  COMSUMER_NUM	2

typedef struct _product
{
	struct list_head list_node;
	int product_id;
}product_t;

struct list_head productList;// 头结点
pthread_mutex_t product_mutex = PTHREAD_MUTEX_INITIALIZER;	// productList 的互斥量
pthread_cond_t  product_cond = PTHREAD_COND_INITIALIZER;	// 条件变量

// 生产者线程,1秒生成一个产品放到链表
void *th_producer(void *arg)
{
	int id = 0;
	while(1)
	{
		product_t *pProduct = (product_t*)malloc(sizeof(product_t));
		pProduct->product_id = id++;
		
		pthread_mutex_lock(&product_mutex);
		list_add_tail(&pProduct->list_node, &productList);
		pthread_cond_signal(&product_cond);
		pthread_mutex_unlock(&product_mutex);
		
		sleep(1);
	}
	
	return NULL;
}

// 消费者线程,1秒消耗掉一个产品
void *th_consumer(void *arg)
{
	while(1)
	{
		pthread_mutex_lock(&product_mutex);
		while(list_empty(&productList)) // 条件不满足
		{
			pthread_cond_wait(&product_cond, &product_mutex);
		}
		// 不为空,则取出一个
		product_t* pProduct = list_entry(productList.next, product_t, list_node);// 获取第一个节点
		printf("consumer[%d] get product id=%d\n", *((int*)arg), pProduct->product_id);
		list_del(productList.next); // 删除第一个节点
		free(pProduct);
		pthread_mutex_unlock(&product_mutex);
	}
	return NULL;
}

int main()
{
	INIT_LIST_HEAD(&productList);	// 初始化链表
	
	// 创建生产者线程
	pthread_t producer_thid;
	pthread_create(&producer_thid, NULL, th_producer, NULL);
	
	// 创建消费者线程
	pthread_t consumer_thid[COMSUMER_NUM];
	int i=0, num[COMSUMER_NUM]={0,};
	for(i=0; i<COMSUMER_NUM; i++)
	{
		num[i] = i;
		pthread_create(&consumer_thid[i], NULL, th_consumer, &num[i]);
	}
	
	// 等待线程
	pthread_join(producer_thid, NULL);
	for(i=0; i<COMSUMER_NUM; i++)
	{
		pthread_join(consumer_thid[i], NULL);
	}
	return 0;
}

在这里插入图片描述

🎄三、条件等待相关思考

✨3.1 pthread_cond_wait 函数做了什么操作?

参考答案:
①条件等待时,pthread_cond_wait 函数做了两个操作:解锁、阻塞。也就是说,会先将传入的互斥量解锁,然后使线程阻塞等待。
②pthread_cond_wait 函数返回时,系统会确保该线程再次持有互斥量(加锁)。

✨3.2 条件变量为什么需要和互斥量一起使用?

参考答案:
①如果某个线程因条件不满足而阻塞等待,那么需要另一个线程来改变条件才能使条件满足。这样的话,这个条件所关联到的数据就是共享数据,没有互斥量,就无法安全地获取和修改共享数据。
②如果仅仅是判断条件,那么在判断条件后解锁即可。但我们需要的是“判断条件、解锁、等待”,为了使这三个步骤之间不会被其他线程打断,我们需要条件变量、互斥量一起使用。至于“判断条件、解锁、等待”不能被打断的原因,看3.4小节。

pthread_mutex_lock(&product_mutex); // 互斥量加锁
while(list_empty(&productList)) 	// 判断条件
{
	pthread_cond_wait(&product_cond, &product_mutex);// 解锁、等待
}
// ...
pthread_mutex_unlock(&product_mutex);// 互斥量释放锁


✨3.3 既然互斥量和条件变量关系如此紧密,为什么不干脆将互斥量变成条件变量的一部分呢?

参考答案:
因为同一个互斥量上可能有不同的条件变量,比如说,有的线程希望当共享数据为单数时唤醒它,有些线程则希望当共享数据为双数时发送通知给它。

这里又多了一个问题,多个条件变量怎么跟一个互斥量共同使用。直接看下面多个条件变量的例子,代码定义了一个互斥量和三个条件变量,根据当前共享数据除以3的余数分别通知三个线程:

// 09_producer_consumer_multiple_cond.c
// gcc 09_producer_consumer_multiple_cond.c -lpthread
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include "linux_list.h"

#define  COMSUMER_NUM	3

typedef struct _product
{
	struct list_head list_node;
	int product_id;
}product_t;

struct list_head productList;// 头结点
pthread_mutex_t product_mutex = PTHREAD_MUTEX_INITIALIZER;	// productList 的互斥量
pthread_cond_t  product_cond = PTHREAD_COND_INITIALIZER;	// 条件变量
pthread_cond_t  product_cond_1 = PTHREAD_COND_INITIALIZER;	// 条件变量, 余数为1
pthread_cond_t  product_cond_2 = PTHREAD_COND_INITIALIZER;	// 条件变量, 余数为2

// 生产者线程,1秒生成一个产品放到链表
void *th_producer(void *arg)
{
	int id = 0;
	while(1)
	{
		product_t *pProduct = (product_t*)malloc(sizeof(product_t));
		pProduct->product_id = id++;
		
		pthread_mutex_lock(&product_mutex);
		list_add_tail(&pProduct->list_node, &productList);
		if((pProduct->product_id % COMSUMER_NUM) == 0)
			pthread_cond_signal(&product_cond);
		else if((pProduct->product_id % COMSUMER_NUM) == 1)
			pthread_cond_signal(&product_cond_1);
		else
			pthread_cond_signal(&product_cond_2);
		pthread_mutex_unlock(&product_mutex);
		
		sleep(1);
	}
	
	return NULL;
}

// 消费者线程,1秒消耗掉一个产品
void *th_consumer(void *arg)
{
	int id = *((int*)arg);
	while(1)
	{
		pthread_mutex_lock(&product_mutex);
		while(list_empty(&productList)) // 条件不满足
		{
			//printf("consumer[%d] cond_wait\n", *((int*)arg));
			if(id == 0)
			{
				pthread_cond_wait(&product_cond, &product_mutex);
			}
			else if(id == 1)
			{
				pthread_cond_wait(&product_cond_1, &product_mutex);
			}
			else
			{
				pthread_cond_wait(&product_cond_2, &product_mutex);
			}
		}
		// 不为空,则取出一个
		product_t* pProduct = list_entry(productList.next, product_t, list_node);// 获取第一个节点
		printf("consumer[%d] get product id=%d\n", *((int*)arg), pProduct->product_id);
		list_del(productList.next); // 删除第一个节点
		free(pProduct);
		pthread_mutex_unlock(&product_mutex);
	}
	return NULL;
}

int main()
{
	INIT_LIST_HEAD(&productList);	// 初始化链表
	
	// 创建生产者线程
	pthread_t producer_thid;
	pthread_create(&producer_thid, NULL, th_producer, NULL);
	
	// 创建消费者线程
	pthread_t consumer_thid[COMSUMER_NUM];
	int i=0, num[COMSUMER_NUM]={0,};
	for(i=0; i<COMSUMER_NUM; i++)
	{
		num[i] = i;
		pthread_create(&consumer_thid[i], NULL, th_consumer, &num[i]);
	}
	
	// 等待线程
	pthread_join(producer_thid, NULL);
	for(i=0; i<COMSUMER_NUM; i++)
	{
		pthread_join(consumer_thid[i], NULL);
	}
	return 0;
}

✨3.4 互斥量加锁的临界区应该包含哪些操作?

参考答案:
首先清楚一点,使用条件变量时需要互斥量是因为多个线程访问、修改共享数据。其次是互斥量加锁的临界区是我们希望连续执行、不被其他线程打断的操作。所以,在条件等待时,互斥量加锁的临界区应该是访问共享数据(查询条件是否满足) --> 解锁、等待(pthread_cond_wait)。在条件唤醒时,互斥量必须加锁的临界区是修改共享数据.

条件等待时,“判断条件、解锁、等待”这三个为什么不可以被打断呢?因为判断条件和pthread_cond_wait之间被打断的话,可能在判断条件之后,调用pthread_cond_wait之前,条件变量就被唤醒了,导致该线程一直等待下去。

下面通过例子来说明为什么“判断条件、解锁、等待”不能被打断,下面例子中,通过宏 SEPARATE_CONT_WAIT 定义为1来模拟判断条件、pthread_cond_wait分开的情况,SEPARATE_CONT_WAIT 定义为0则表示判断条件、pthread_cond_wait不会被打断。

// 09_producer_consumer_cond_loss.c
// gcc 09_producer_consumer_cond_loss.c -lpthread
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include "linux_list.h"

#define  COMSUMER_NUM	1
#define  SEPARATE_CONT_WAIT	1 // 为1表示分开 判断条件、pthread_cond_wait

typedef struct _product
{
	struct list_head list_node;
	int product_id;
}product_t;

struct list_head productList;// 头结点
pthread_mutex_t product_mutex = PTHREAD_MUTEX_INITIALIZER;	// productList 的互斥量
pthread_cond_t  product_cond = PTHREAD_COND_INITIALIZER;	// 条件变量

// 生产者线程,只生成一个产品放到链表
void *th_producer(void *arg)
{
	int id = 0;
	//while(1)
	{
		product_t *pProduct = (product_t*)malloc(sizeof(product_t));
		pProduct->product_id = id++;
		
		pthread_mutex_lock(&product_mutex);
		list_add_tail(&pProduct->list_node, &productList);
		pthread_cond_signal(&product_cond);
		pthread_mutex_unlock(&product_mutex);
		printf("pthread_cond_signal\n");
		
		sleep(1);
	}
	
	return NULL;
}

// 消费者线程,1秒消耗掉一个产品
void *th_consumer(void *arg)
{
	while(1)
	{
		pthread_mutex_lock(&product_mutex);
		while(list_empty(&productList)) // 条件不满足
		{
		#if SEPARATE_CONT_WAIT
			pthread_mutex_unlock(&product_mutex);
			sleep(3);  // 加大延时,模拟 判断条件、pthread_cond_wait 之间被打断的情况
			pthread_mutex_lock(&product_mutex);
		#endif
			printf("pthread_cond_wait\n");
			pthread_cond_wait(&product_cond, &product_mutex);
		}
		// 不为空,则取出一个
		product_t* pProduct = list_entry(productList.next, product_t, list_node);// 获取第一个节点
		printf("consumer[%d] get product id=%d\n", *((int*)arg), pProduct->product_id);
		list_del(productList.next); // 删除第一个节点
		free(pProduct);
		pthread_mutex_unlock(&product_mutex);
	}
	return NULL;
}

int main()
{
	INIT_LIST_HEAD(&productList);	// 初始化链表
	
	// 创建生产者线程
	pthread_t producer_thid;
	pthread_create(&producer_thid, NULL, th_producer, NULL);
	
	// 创建消费者线程
	pthread_t consumer_thid[COMSUMER_NUM];
	int i=0, num[COMSUMER_NUM]={0,};
	for(i=0; i<COMSUMER_NUM; i++)
	{
		num[i] = i;
		pthread_create(&consumer_thid[i], NULL, th_consumer, &num[i]);
	}
	
	// 等待线程
	pthread_join(producer_thid, NULL);
	for(i=0; i<COMSUMER_NUM; i++)
	{
		pthread_join(consumer_thid[i], NULL);
	}
	return 0;
}

下面是"判断条件、pthread_cond_wait" 被打断的运行结果,会出现唤醒丢失,一直等待:
在这里插入图片描述

✨3.5 为什么条件等待时,使用while来判断条件,而不是用if ?

参考答案:
为了让线程被唤醒后,再次判断条件是否满足。这样做是因为存在虚假唤醒,也就是说,条件尚未满足, pthread_cond_wait就返回了。

下面使用pthread_cond_broadcast来模拟虚假唤醒,看看while和if的区别:
1、创建2个线程,运行后进入条件等待;
2、创建1个线程,5秒后使用 pthread_cond_broadcast 唤醒所有等待线程;
3、先醒来的线程,醒来后,条件是满足的,获取到数据。后面醒来的线程,由于数据被前面的线程拿走了,此时条件应该不满足的,但它没再次判断,直接取数据导致程序出问题。

// 09_producer_consumer_cond_brocast.c
// gcc 09_producer_consumer_cond_brocast.c -lpthread
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include "linux_list.h"

#define  COMSUMER_NUM	2

typedef struct _product
{
	struct list_head list_node;
	int product_id;
}product_t;

struct list_head productList;// 头结点
pthread_mutex_t product_mutex = PTHREAD_MUTEX_INITIALIZER;	// productList 的互斥量
pthread_cond_t  product_cond = PTHREAD_COND_INITIALIZER;	// 条件变量

// 生产者线程,5秒后生成一个产品放到链表
void *th_producer(void *arg)
{
	int id = 0;
	//while(1)
	sleep(5);
	{
		product_t *pProduct = (product_t*)malloc(sizeof(product_t));
		pProduct->product_id = id++;
		
		pthread_mutex_lock(&product_mutex);
		list_add_tail(&pProduct->list_node, &productList);
		pthread_cond_broadcast(&product_cond);
		pthread_mutex_unlock(&product_mutex);
		
		sleep(1);
	}
	
	return NULL;
}

// 消费者线程,1秒消耗掉一个产品
void *th_consumer(void *arg)
{
	while(1)
	{
		pthread_mutex_lock(&product_mutex);
		if(list_empty(&productList)) // 条件不满足
		//while(list_empty(&productList)) // 条件不满足
		{
			pthread_cond_wait(&product_cond, &product_mutex);
		}
		// 不为空,则取出一个
		product_t* pProduct = list_entry(productList.next, product_t, list_node);// 获取第一个节点
		printf("consumer[%d] get product id=%d\n", *((int*)arg), pProduct->product_id);
		list_del(productList.next); // 删除第一个节点
		free(pProduct);
		pthread_mutex_unlock(&product_mutex);
	}
	return NULL;
}

int main()
{
	INIT_LIST_HEAD(&productList);	// 初始化链表
	
	// 创建生产者线程
	pthread_t producer_thid;
	pthread_create(&producer_thid, NULL, th_producer, NULL);
	
	// 创建消费者线程
	pthread_t consumer_thid[COMSUMER_NUM];
	int i=0, num[COMSUMER_NUM]={0,};
	for(i=0; i<COMSUMER_NUM; i++)
	{
		num[i] = i;
		pthread_create(&consumer_thid[i], NULL, th_consumer, &num[i]);
	}
	
	// 等待线程
	pthread_join(producer_thid, NULL);
	for(i=0; i<COMSUMER_NUM; i++)
	{
		pthread_join(consumer_thid[i], NULL);
	}
	return 0;
}

在这里插入图片描述

🎄四、条件唤醒相关思考

✨4.1 先唤醒后解锁,还是先解锁后唤醒?

参考答案:
“先唤醒后解锁” 会比 “先解锁后唤醒” 的效率更低一点。条件等待的线程会从pthread_cond_wait函数返回,pthread_cond_wait函数返回时,系统会确保该线程再次持有互斥量(加锁)。“先唤醒后解锁” 会导致线程醒来后,由于互斥量还没释放,需要继续等待互斥量释放后才能继续执行。而 “先解锁后唤醒” 则不会出现这种情况。但是,实际使用过程中,这两种都可以,不用特别在意这点效率。

✨4.2 使用 pthread_cond_broadcast 唤醒所有线程后,各个线程是怎样接着运行的?

参考答案:
pthread_cond_broadcast 唤醒所有线程后,被唤醒的线程都会从 pthread_cond_wait 函数返回,但要从 pthread_cond_wait 返回需要先拿到互斥量并加锁。于是,各个线程会先去争夺互斥量,第一个抢到互斥量的线程先从 pthread_cond_wait 返回,继续往下执行,其他的线程则阻塞等待继续争夺互斥量。就这样,各个线程依次的抢到互斥量,再从 pthread_cond_wait 返回,往下执行。

在这里插入图片描述

🎄五、总结

本文总结了使用条件变量过程中,一些遇到的问题,并给出了一些自认为正确的参考答案。如果有不同想法,欢迎留言探讨。

在这里插入图片描述
如果文章有帮助的话,点赞👍、收藏⭐,支持一波,谢谢 😁😁😁

  • 14
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wkd_007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值