1 //===-- main.c --------------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #include <pthread.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 
13 char *pointer;
14 
15 void *nothing(void *p) {
16     return NULL;
17 }
18 
19 void *f1(void *p) {
20     pointer[0] = 'x';
21     sleep(100);
22     return NULL;
23 }
24 
25 void *f2(void *p) {
26     pointer[0] = 'y';
27     sleep(100);
28     return NULL;
29 }
30 
31 int main (int argc, char const *argv[])
32 {
33     pointer = (char *)malloc(10);
34 
35     for (int i = 0; i < 3; i++) {
36         pthread_t t;
37         pthread_create(&t, NULL, nothing, NULL);
38         pthread_join(t, NULL);
39     }
40 
41     pthread_t t1;
42     pthread_create(&t1, NULL, f1, NULL);
43 
44     for (int i = 0; i < 3; i++) {
45         pthread_t t;
46         pthread_create(&t, NULL, nothing, NULL);
47         pthread_join(t, NULL);
48     }
49 
50     pthread_t t2;
51     pthread_create(&t2, NULL, f2, NULL);
52 
53     pthread_join(t1, NULL);
54     pthread_join(t2, NULL);
55 
56     return 0;
57 }
58