社区讨论

求问thread

题目总版参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@m1vkfmav
此快照首次捕获于
2024/10/05 10:59
去年
此快照最后确认于
2025/11/04 18:01
4 个月前
查看原帖
理论上thread应该是同步进行的,但为什么程序先输出了10000次IAKIOI再输出了10000次IAKCSP?
CPP
#include <bits/stdc++.h>
#include <thread>
#define int long long
using namespace std;
void IOI(){
	for(int i=0;i<10000;i++) cout<<"IAKIOI";
} 
void csp(int a){
	if(a==1){
		thread b(IOI);
		b.join();
	}
	for(int i=0;i<10000;i++) cout<<"IAKCSP";
}
signed main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
	thread a(csp,1);
	a.join();
  return 0;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...