-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathaccess_thread.c
More file actions
49 lines (45 loc) · 1.17 KB
/
access_thread.c
File metadata and controls
49 lines (45 loc) · 1.17 KB
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
#include <pthread.h>
#include <errno.h>
#include "common.h"
_Thread_local int l = 3;
int64_t N = 500000;
void *thread_fn(void* arg) {
int k = 0;
for (volatile int i = 0; i < N; i++) {
if ((i % (N/10)) == 0) {
printf("------- Hello Thread | Self: %d, K: %d\n", (int)pthread_self(), k++);
}
}
char* path = (char*) arg;
if (!access(path, F_OK)) {
printf("OK access rights -- Errno: %s\n", strerror(errno));
} else {
printf("No access rights -- Errno: %s\n", strerror(errno));
}
return NULL;
}
int main(int argc, char* argv[]) {
char path1[100], path2[100];
if (argc == 3) {
strcpy(path1, argv[1]);
strcpy(path2, argv[2]);
} else {
printf("Error in argc(must be 3)\n");
}
pthread_t tid;
if (pthread_create(&tid, NULL, thread_fn, path2)) {
printf("Error\n");
}
int k = 0;
for (volatile int i = 0; i < N*2; i++) {
if ((i % (N/10)) == 0) {
printf("------ Hello Parent | Self: %d, K: %d\n", (int)pthread_self(), k++);
}
}
if (!access(path1, F_OK)) {
printf("OK access rights -- Errno: %s\n", strerror(errno));
} else {
printf("No access rights -- Errno: %s\n", strerror(errno));
}
return 0;
}