Implementace vyhradniho rezimu
[mirrors/Programs.git] / c / pthread_extra / test_pause.c
1 #include <signal.h>
2 #include <pthread.h>
3 #include <pthread_extra.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <assert.h>
7 #include <unistd.h>
8
9 void *thread_test(void *arg) {
10 //Whole process dies if you kill thread immediately before it is pausable
11 //pthread_pause_enable();
12 while(1) {
13 usleep(1000*300);
14 printf("Running%s!\n", (char *)arg);
15 }
16 }
17
18 int main() {
19
20 pthread_t a, b;
21 pthread_pause_enable(); //Will get inherited by all threads from now on
22 //That way you can be sure it is pausable immediately
23 pthread_extra_create(&a, NULL, thread_test, " A");
24 pthread_extra_create(&b, NULL, thread_test, " B");
25 //sleep(1);
26
27 //printf("OK\n");
28 /*
29 for(int32_t i = 1;i>0;i++) {
30 pthread_pause(a);
31 pthread_pause(a);
32 pthread_unpause(a);
33 pthread_unpause(a);
34 }
35 */
36 /*
37 exit(23);
38 pthread_pause(a);
39 pthread_unpause(b);
40 */
41
42 while(1) {
43 pthread_pause(b);
44 pthread_unpause(a);
45 printf("SWITCH A:\n");
46 sleep(2);
47
48 printf("SWITCH B:\n");
49 pthread_pause(a);
50 pthread_unpause(b);
51 sleep(2);
52
53 printf("SWITCH A+B:\n");
54 pthread_unpause(a);
55 pthread_unpause(b);
56 sleep(1);
57
58 printf("SWITCH MAIN ONLY:\n");
59 pthread_pause_all();
60 sleep(1);
61 printf("SWITCH MAIN A+B:\n");
62 pthread_unpause_all();
63 sleep(1);
64 }
65
66 pthread_join(a, NULL);
67 pthread_join(b, NULL);
68 printf("DIEDED!\n");
69 }
This page took 0.28379 seconds and 4 git commands to generate.