-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
125 lines (86 loc) · 2.11 KB
/
main.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
/* https://opensource.com/article/19/5/how-write-good-c-main-function*/
/* main.c */
/* 0 copyright/licensing */
/* 1 includes */
/* 2 defines */
/* 3 external declarations */
/* 4 typedefs */
/* 5 global variable declarations */
/* 6 function prototypes */
/*author: ardavic*/
# include <stdio.h>
# include <pthread.h>
typedef struct{
pthread_t thread;
int mutex;
}foobar;
int InitFoobar(foobar* foo);
void FreeFoobar(foobar* foo);
typedef struct{
int value;
}Binary;
void setBinaryTrue(Binary binaryobj, int value);
void setBinaryFalse(Binary binaryobj, int value);
void* doSomeThing(void *param);
int counter;
int main(int argc, char *argv[]) {
doSomeThing(NULL);
return 0;
};
int mainCOPY() {
/*
int i = 0;
int err;
pthread_mutex_t* lock;
pthread_mutex_lock(&lock);
if (pthread_mutex_init(&lock, NULL) != 0)
{
printf("\n mutex init failed\n");
return 1;
}
while(i < 2)
{
i++;
}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy(&lock);
*/
//pthread_mutex_lock(&lock);
//foobar fooStruct;
//InitFoobar(&fooStruct);
//FreeFoobar(&fooStruct);
return 0;
};
int InitFoobar(foobar* foo){
/*
//err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
pthread_t *pthread = foo -> thread;
int err = pthread_create(pthread, NULL, &doSomeThing, NULL);
if (err != 0){
printf("can't create thread\n");
return err;
}else {
return 1;
} */
//oneCreate(&foo->mutex);
}
void FreeFoobar(foobar* foo){
//oneDestroy(foo->mutex);
}
/* 8 function declarations */
void* doSomeThing(void *param){
pthread_attr_t tattr;
pthread_t tid;
extern void *start_routine(void *arg);
void *arg;
int ret;
//pthread_mutex_lock(&lock);
unsigned long i = 0;
counter += 1;
printf("\n Job %d started\n", counter);
for(i=2; i<(0xFFFFFFFF);i=i*i);
printf("\n Job %d finished\n", counter);
//pthread_mutex_unlock(&lock);
return NULL;
}