Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

视觉—多线程作业 from 闫皓禹 #1

Open
Ayuyhy opened this issue Nov 27, 2023 · 0 comments
Open

视觉—多线程作业 from 闫皓禹 #1

Ayuyhy opened this issue Nov 27, 2023 · 0 comments

Comments

@Ayuyhy
Copy link

Ayuyhy commented Nov 27, 2023

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<thread>
#include<stdlib.h>
#include<time.h>
#include<mutex>
#include<Windows.h>
#define NELL 0
using namespace std;
mutex mtx;
int main() {
	int x;
	Adam:
	void input(int* p);
	void output(int* k);
	thread in(input, &x);
	in.join( );
	thread out(output, &x);
	out.join();
	Sleep(1000);
	goto Adam;
	return 0;
}
void input(int* p) {
	mtx.lock();
	srand(time(NELL));
	*p = rand() % 100 + 1;
	mtx.unlock();
}
void output(int* k) {
	mtx.lock();
	if(*k%2==0)
	cout << *k << endl;
	mtx.unlock();
}
[多线程处理.log](https://github.com/Adam-QLUT/cpp_mutex_homework/files/13475888/default.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant