-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
48 lines (38 loc) · 1.07 KB
/
main.cc
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
#include <cstdarg>
#include <cstdio>
#include <iostream>
using namespace std;
#include <pthread.h>
#include <sched.h>
#include "log.h"
void *producer(void *arg)
{
int *base = (int *)arg;
for (int i = *base; i < *base + 1000000; i++){
log_debug("%d, %s", i, "producer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
sched_yield();
}
printf("producer exit\n");
//SingletonLog::get_instance()->close_log();
return NULL;
}
void *consumer(void *arg)
{
SingletonLog::get_instance()->write_log_to_file();
return NULL;
}
int main(int argc, char *argv[])
{
SingletonLog::get_instance()->open_log("./log/log", SingletonLog::DEBUG, 1000);
pthread_t aid, bid, cid, did;
int a = 0, b = 1000000, c = 200000;
pthread_create(&aid, NULL, producer, &a);
pthread_create(&cid, NULL, producer, &b);
pthread_create(&did, NULL, producer, &c);
pthread_create(&bid, NULL, consumer, NULL);
pthread_join(aid, NULL);
pthread_join(cid, NULL);
pthread_join(did, NULL);
pthread_join(bid, NULL);
return 0;
}