-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.cpp
More file actions
51 lines (40 loc) · 899 Bytes
/
test.cpp
File metadata and controls
51 lines (40 loc) · 899 Bytes
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
51
#include "timer.h"
#include <pthread.h>
#include <iostream>
#include <unistd.h>
using namespace std;
SafeTimer<int64_t,int64_t> timer;
int32_t print(int64_t uid, int64_t param)
{
static timeval tv;
gettimeofday(&tv, 0);
cout << "out uid:" << uid << "|" << tv.tv_sec <<endl;
return 0;
}
void *producer(void *)
{
for (size_t i = 0; i < 100000; i++) {
int64_t uid = rand();
static timeval tv;
gettimeofday(&tv, 0);
cout << "in uid:" << uid << "|" << tv.tv_sec <<endl;
int32_t ret = timer.addEvent(print, time(NULL) + 1, uid, 0);
if (ret < 0) {
cout << "in uid error:" << endl;
}
}
pthread_exit(0);
}
int main()
{
timer.init();
pthread_t tid;
pthread_create(&tid, NULL, producer, NULL);
pthread_create(&tid, NULL, producer, NULL);
pthread_create(&tid, NULL, producer, NULL);
pthread_create(&tid, NULL, producer, NULL);
for (; ;) {
sleep(1);
}
return 0;
}