Assert for missing feature
[mirrors/Programs.git] / c / pthread_extra / test_pause.c
CommitLineData
a8e71e8f
TM
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
9void *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
18int 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_create(&a, NULL, thread_test, " A");
24 pthread_create(&b, NULL, thread_test, " B");
24286ba9
TM
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 */
a8e71e8f
TM
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
59 pthread_join(a, NULL);
60 pthread_join(b, NULL);
61 printf("DIEDED!\n");
62}
This page took 0.214676 seconds and 4 git commands to generate.