1 /* Tests for cancelation handling. */
12 pthread_barrier_t bar
;
19 int nr
= (int) (long int) arg
;
21 char *cp
= stpcpy (s
, "cleanup ");
24 __libc_lseek (fd
, 0, SEEK_END
);
25 __libc_write (fd
, s
, cp
- s
);
32 pthread_cleanup_push (cleanup
, (void *) (long int) 1);
34 pthread_cleanup_pop (0);
41 pthread_cleanup_push (cleanup
, (void *) (long int) a
);
44 pthread_cleanup_pop (0);
51 pthread_cleanup_push (cleanup
, (void *) (long int) 2);
52 inner ((int) (long int) arg
);
54 pthread_cleanup_pop (0);
58 /* This does not work yet. */
59 volatile int cleanupokcnt
;
71 pthread_cleanup_push (cleanupok
, (void *) (long int) 4);
72 inner ((int) (long int) arg
);
74 pthread_cleanup_pop (0);
81 pthread_cleanup_push (cleanupok
, (void *) (long int) a
);
83 pthread_cleanup_pop (0);
90 pthread_cleanup_push (cleanupok
, (void *) (long int) 6);
91 innerok ((int) (long int) arg
);
92 pthread_cleanup_pop (0);
98 main (int argc
, char *argv
[])
104 const char template[] = "thtstXXXXXX";
108 prefix
= argc
> 1 ? argv
[1] : "";
109 tmp
= (char *) alloca (strlen (prefix
) + sizeof template);
110 strcpy (stpcpy (tmp
, prefix
), template);
115 printf ("cannot create temporary file: %m");
120 err
= pthread_barrier_init (&bar
, NULL
, 2);
123 printf ("cannot create barrier: %s\n", strerror (err
));
128 err
= pthread_create (&td
, NULL
, t1
, NULL
);
131 printf ("cannot create thread t1: %s\n", strerror (err
));
135 err
= pthread_join (td
, NULL
);
138 printf ("cannot join thread: %s\n", strerror (err
));
142 err
= pthread_create (&td
, NULL
, t2
, (void *) 3);
145 printf ("cannot create thread t2: %s\n", strerror (err
));
149 err
= pthread_join (td
, NULL
);
152 printf ("cannot join thread: %s\n", strerror (err
));
156 err
= pthread_create (&td
, NULL
, t3
, (void *) 5);
159 printf ("cannot create thread t3: %s\n", strerror (err
));
163 err
= pthread_join (td
, NULL
);
166 printf ("cannot join thread: %s\n", strerror (err
));
171 err
= pthread_create (&td
, NULL
, t4
, (void *) 7);
174 printf ("cannot create thread t4: %s\n", strerror (err
));
178 err
= pthread_join (td
, NULL
);
181 printf ("cannot join thread: %s\n", strerror (err
));
185 if (fstat64 (fd
, &st
) < 0)
187 printf ("cannot stat temporary file: %m\n");
190 else if (st
.st_size
!= 0)
193 puts ("some cleanup handlers ran:");
195 __lseek (fd
, 0, SEEK_SET
);
198 ssize_t n
= read (fd
, buf
, sizeof buf
);
201 write (STDOUT_FILENO
, buf
, n
);
206 // if (cleanupokcnt != 3) will be three once t3 runs
207 if (cleanupokcnt
!= 2)
209 printf ("cleanupokcnt = %d\n", cleanupokcnt
);