Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libpthread / find / findthreads.c
blobc98258c348498d29ef42982abd290517c20aba7c
1 /* $NetBSD$ */
3 #include <err.h>
4 #include <pthread.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <string.h>
9 #include <sys/resource.h>
11 static void *
12 f(void *arg)
15 sleep(1000);
16 return 0;
19 #define NUM 100
20 int
21 main(int argc, char **argv)
23 pthread_t thr[NUM];
24 int seed, i, j, res, errors;
25 char nam[20];
26 struct rlimit sl;
28 if (argc > 1)
29 seed = atoi(argv[1]);
30 else
31 seed = time(0);
32 srandom(seed);
33 getrlimit(RLIMIT_STACK, &sl);
35 errors = 0;
36 for (i = 0; i < NUM; i++) {
37 res = pthread_create(&thr[i], 0, f, 0);
38 if (res)
39 errx(1, "pthread_create: %s", strerror(res));
40 for (j = 0; j <= i; j++) {
41 res = pthread_getname_np(thr[j], nam, sizeof(nam));
42 if (res) {
43 warnx("getname(%d/%d): %s\n", i, j,
44 strerror(res));
45 errors++;
48 if (errors)
49 break;
50 malloc((random() & 7) * sl.rlim_cur);
52 if (errors) {
53 printf("%d errors\n", errors);
54 if (argc <= 1)
55 printf("seed was %d\n", seed);
57 return (!!errors);