| 1 | #include <pthread.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | char *pointer; |
| 7 | |
| 8 | void *nothing(void *p) { |
| 9 | return NULL; |
| 10 | } |
| 11 | |
| 12 | void *f1(void *p) { |
| 13 | pointer[0] = 'x'; |
| 14 | sleep(seconds: 100); |
| 15 | return NULL; |
| 16 | } |
| 17 | |
| 18 | void *f2(void *p) { |
| 19 | pointer[0] = 'y'; |
| 20 | sleep(seconds: 100); |
| 21 | return NULL; |
| 22 | } |
| 23 | |
| 24 | int main (int argc, char const *argv[]) |
| 25 | { |
| 26 | pointer = (char *)malloc(size: 10); |
| 27 | |
| 28 | for (int i = 0; i < 3; i++) { |
| 29 | pthread_t t; |
| 30 | pthread_create(newthread: &t, NULL, start_routine: nothing, NULL); |
| 31 | pthread_join(th: t, NULL); |
| 32 | } |
| 33 | |
| 34 | pthread_t t1; |
| 35 | pthread_create(newthread: &t1, NULL, start_routine: f1, NULL); |
| 36 | |
| 37 | for (int i = 0; i < 3; i++) { |
| 38 | pthread_t t; |
| 39 | pthread_create(newthread: &t, NULL, start_routine: nothing, NULL); |
| 40 | pthread_join(th: t, NULL); |
| 41 | } |
| 42 | |
| 43 | pthread_t t2; |
| 44 | pthread_create(newthread: &t2, NULL, start_routine: f2, NULL); |
| 45 | |
| 46 | pthread_join(th: t1, NULL); |
| 47 | pthread_join(th: t2, NULL); |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |