-
Notifications
You must be signed in to change notification settings - Fork 2
/
T86.cpp
50 lines (42 loc) · 1.07 KB
/
T86.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//TODO C++ 条件变量+互斥锁 == Java版本的(notify 与 wait操作)
#include <iostream>
#include "sage_queue_tool.h"
using namespace std;
SafeQueueClass<int> sq;
void *getMethod(void *pVoid) {
while (true) {
printf("getMethod\n");
int value;
sq.get(value);
printf("消费者get 得到的数据是%d\n", value);
if (-1 == value) {
printf("消费者 get 全部执行完毕");
break;
}
}
return 0;
}
void *setMethod(void *pVoid) {
while (true) {
printf("setMethod\n");
printf("请输入要生成的信息:\n");
int value;
cin >> value;
sq.add(value);
if (-1 == value) {
sq.add(value);
printf("生产者set 全部执行完毕");
break;
}
}
return 0;
}
int main86() {
pthread_t pthreadGet;
pthread_create(&pthreadGet,0,getMethod,0);
pthread_t pthreadSet;
pthread_create(&pthreadSet,0,setMethod,0);
pthread_join(pthreadGet,0);
pthread_join(pthreadSet,0);
return 0;
}