-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_threads.c
More file actions
85 lines (63 loc) · 1.46 KB
/
test_threads.c
File metadata and controls
85 lines (63 loc) · 1.46 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
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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sched.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <time.h>
#include <fcntl.h>
#include <pthread.h>
#define OUTNAME "file.txt"
#define BUF_MAX 256
char buf[BUF_MAX];
/* this also runs in the HRT */
static void *
routine1 (void * in)
{
printf("lowest child active\n");
return NULL;
}
/* this runs in the HRT */
static void *
routine (void * in)
{
pthread_t t;
pthread_create(&t, NULL, routine1, NULL);
#define SIZE (1024*1024*8)
printf("Child thread is running\n");
void * x = malloc(SIZE);
if (!x) {
fprintf(stderr, "Could not (libc) malloc pages\n");
return NULL;
}
memset(x, 0, SIZE);
printf("opening a file\n");
FILE * fd = fopen("newfile.txt", "w+");
fprintf(fd, "THIS IS A TEST\n");
fclose(fd);
printf("HRT thread done!\n");
if (pthread_join(t, NULL) != 0) {
fprintf(stderr, "ERROR joining\n");
}
return NULL;
}
/* this runs in the ROS */
int
main (int argc, char * argv[])
{
pthread_t t;
printf("Creating child thread in HRT mode\n");
pthread_create(&t, NULL, routine, NULL);
printf("Joining child\n");
#if 0
while (1) {
//printf("main thread looping\n");
}
#endif
if (pthread_join(t, NULL) != 0) {
fprintf(stderr, "ERROR joining in main thread\n");
}
printf("Joined child (HRT) thread and exiting.\n");
return 0;
}