-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patht.c
137 lines (135 loc) · 3.11 KB
/
t.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <stdio.h>
// #include "tienlen.h"
// #include "connect.h"
#include <signal.h>
#include <ctype.h>
#include <pthread.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
// #include <utils.h>
#include "include/point.h"
// struct test
// {
// int a;
// int b;
// };
// struct test f()
// {
// struct test t;
// t.a = 1;
// t.b = 2;
// return t;
// }
// const char *f1()
// {
// return "Hello World!";
// }
void *test(void *data);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
// int i = 0;
void *test(void *data)
{
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond, &mutex);
for (int i = 0; i < 15; i++)
{
printf("%d test%d\n", i, (int)data);
}
pthread_mutex_unlock(&mutex);
return NULL;
}
void *test2(void *data)
{
for (int i = 0; i < 15; i)
{
pthread_mutex_lock(&mutex);
if (i == 5)
{
pthread_cond_signal(&cond);
puts("signal");
// sleep(1);
i++;
}
else
{
printf("%d test2\n", i++);
}
pthread_mutex_unlock(&mutex);
}
return NULL;
}
int generateID()
{
static int s_id = 0;
auto int b = 0;
return ++s_id;
}
void print()
{
for (int i = 0; i < 10; i++)
{
sleep(1);
printf("%s\n", "Hello World!");
}
}
int main(int argc, char const *argv[])
{
// Card card1 = createCard(DIAMOND, TEN);
// Card card2 = createCard(HEART, KING);
// Card card3 = createCard(SPADE, TWO);
// Card cards[] = {card1, card2, card3};
// char str[100];
// cardsToString(cards, 3, str);
// printf("%s\n", str);
// Card cards1[10];
// int size;
// stringToCards(str, cards1, &size);
// printf("%d\n", size);
// for (int i = 0; i < size; i++)
// {
// printf("Card %d: %d %d\n", i + 1, cards[i].suit, cards[i].value);
// }
// Req req = createPlayRequest(cards, 3);
// ReqD data = req.data;
// PlayReqD playData = data.play;
// for (int i = 0; i < playData.cardSize; i++)
// {
// printf("Card %d: %d %d - %s\n", i + 1, playData.cards[i].suit, playData.cards[i].value, cardToString(playData.cards[i]));
// }
// return 0;
// printf("%d\n", atoi(argv[1]));
// pthread_t tid, tid1;
// pthread_create(&tid, NULL, &print, NULL);
// pthread_create(&tid1, NULL, test2, (void *)2);
// pthread_cond_signal(&cond);
// pthread_join(tid1, NULL);
// pthread_join(tid, NULL);
// pthread_detach(tid);
// pthread_detach(tid1);
// printf("Hello World 1!\n");
// printf("Hello World 2!\n");
// sleep(6);
// pthread_cancel(tid);
// int result[52];
// randArray(0, 51, result, 52);
// for (int i = 0; i < 52; i++)
// {
// printf("%d ", result[i]);
// }
// puts("");
// printf("%d\n", getPoint(argv[1]));
exportPoint(argv[1], (unsigned char)atoi(argv[2]));
return 0;
}
// void f()
// {
// puts("Hello World!");
// }
// int main()
// {
// signal(SIGQUIT, (void *)f);
// sleep(10000);
// return (0);
// }