Skip to content

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

@Ayuyhy

Description

@Ayuyhy
#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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions