-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
#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)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels