多线程学习记录1

这篇博客记录了作者在网易云课堂上学习C++多线程的初步体验,涵盖了多进程通信(如文件、管道、消息队列)和多线程通信(共享内存)的概念。文中提到了使用对象初始化线程的示例,并探讨了数据互斥和竞争的问题。
摘要由CSDN通过智能技术生成

网易云课堂上有门c++多线程的入门教程,学习过程在此记录下。

并发编程:

1.多进程(通信:文件,管道,消息队列);2.多线程(通信:共享内存)。

code1:

#include <iostream>
#include <thread>
void test_funtion(){
	std::cout << "test test test!" <<std:: endl;
}
int main()
{
	std::thread t1(test_funtion);
	//t1.join();//main线程等待t1线程完成后继续向下执行
	t1.detach();//t1还没来得及输出,主程序就结束了,所以没有输出。线程detach之后,不能再join。
	if (t1.joinable()){
		t1.join();
	}
	return 0;
}
code2:

#include <iostream>
#include <thread>
void test_funtion(){
	std::cout << "test_funtion!" <<std:: endl;
}
int main()
{
	std::thread t1(test_funtion);
	for (int i = 0; i < 100;++i)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值