-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaths.c
50 lines (38 loc) · 817 Bytes
/
paths.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
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#define NUM_ITS (1 << 20)
#define NUM_THREADS 8
static FILE* f;
static void paths(int nonce)
{
if (nonce < 2)
fputs("path: nonce < 2\n", f);
else
fputs("path: nonce >= 2\n", f);
}
static void* thread(void* pargc)
{
int argc = (intptr_t)pargc;
int i;
for (i = 0; i < NUM_ITS; ++i) {
paths(argc);
}
return NULL;
}
int main(int argc, char** argv)
{
pthread_t t[NUM_THREADS];
int i;
f = fopen("/dev/null", "w");
for (i = 0; i < NUM_THREADS; ++i) {
pthread_create(&t[i], NULL, thread, (void*)(intptr_t)argc);
}
for (i = 0; i < NUM_ITS; ++i) {
paths(argc);
}
for (i = 0; i < NUM_THREADS; ++i) {
pthread_join(t[i], NULL);
}
return 0;
}