1 /* Tests for cancelation handling. */
12 pthread_barrier_t bar
;
18 int nr
= (int) (long int) arg
;
20 char *cp
= stpcpy (s
, "cleanup ");
23 __libc_lseek (fd
, 0, SEEK_END
);
24 __libc_write (fd
, s
, cp
- s
);
31 pthread_cleanup_push (cleanup
, (void *) (long int) 1);
33 pthread_cleanup_pop (0);
40 pthread_cleanup_push (cleanup
, (void *) (long int) a
);
43 pthread_cleanup_pop (0);
50 pthread_cleanup_push (cleanup
, (void *) (long int) 2);
51 inner ((int) (long int) arg
);
53 pthread_cleanup_pop (0);
57 /* This does not work yet. */
58 volatile int cleanupokcnt
;
70 pthread_cleanup_push (cleanupok
, (void *) (long int) 4);
71 inner ((int) (long int) arg
);
73 pthread_cleanup_pop (0);
80 pthread_cleanup_push (cleanupok
, (void *) (long int) a
);
82 pthread_cleanup_pop (0);
89 pthread_cleanup_push (cleanupok
, (void *) (long int) 6);
90 innerok ((int) (long int) arg
);
91 pthread_cleanup_pop (0);
97 main (int argc
, char *argv
[])
103 const char template[] = "thtstXXXXXX";
107 prefix
= argc
> 1 ? argv
[1] : "";
108 tmp
= (char *) alloca (strlen (prefix
) + sizeof template);
109 strcpy (stpcpy (tmp
, prefix
), template);
114 printf ("cannot create temporary file: %m");
119 err
= pthread_barrier_init (&bar
, NULL
, 2);
122 printf ("cannot create barrier: %s\n", strerror (err
));
127 err
= pthread_create (&td
, NULL
, t1
, NULL
);
130 printf ("cannot create thread t1: %s\n", strerror (err
));
134 err
= pthread_join (td
, NULL
);
137 printf ("cannot join thread: %s\n", strerror (err
));
141 err
= pthread_create (&td
, NULL
, t2
, (void *) 3);
144 printf ("cannot create thread t2: %s\n", strerror (err
));
148 err
= pthread_join (td
, NULL
);
151 printf ("cannot join thread: %s\n", strerror (err
));
155 err
= pthread_create (&td
, NULL
, t3
, (void *) 5);
158 printf ("cannot create thread t3: %s\n", strerror (err
));
162 err
= pthread_join (td
, NULL
);
165 printf ("cannot join thread: %s\n", strerror (err
));
170 err
= pthread_create (&td
, NULL
, t4
, (void *) 7);
173 printf ("cannot create thread t3: %s\n", strerror (err
));
177 err
= pthread_join (td
, NULL
);
180 printf ("cannot join thread: %s\n", strerror (err
));
184 if (fstat64 (fd
, &st
) < 0)
186 printf ("cannot stat temporary file: %m\n");
189 else if (st
.st_size
!= 0)
192 puts ("some cleanup handlers ran:");
194 __lseek (fd
, 0, SEEK_SET
);
197 ssize_t n
= read (fd
, buf
, sizeof buf
);
200 write (STDOUT_FILENO
, buf
, n
);
205 // if (cleanupokcnt != 3) will be three once t3 runs
206 if (cleanupokcnt
!= 2)
208 printf ("cleanupokcnt = %d\n", cleanupokcnt
);