diff options
author | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
---|---|---|
committer | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
commit | eb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch) | |
tree | edb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libc/stdio_threading/include/local.h | |
parent | 247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff) | |
download | openbsd-tb_20250414.tar.gz openbsd-tb_20250414.tar.bz2 openbsd-tb_20250414.zip |
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/regress/lib/libc/stdio_threading/include/local.h')
-rw-r--r-- | src/regress/lib/libc/stdio_threading/include/local.h | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/src/regress/lib/libc/stdio_threading/include/local.h b/src/regress/lib/libc/stdio_threading/include/local.h deleted file mode 100644 index 7a7822a452..0000000000 --- a/src/regress/lib/libc/stdio_threading/include/local.h +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <err.h> | ||
18 | #include <errno.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | #include <string.h> | ||
22 | #include <unistd.h> | ||
23 | #include <pthread.h> | ||
24 | |||
25 | #define THREAD_COUNT 64 | ||
26 | |||
27 | #define TEXT "barnacles" | ||
28 | #define TEXT_N "barnacles\n" | ||
29 | |||
30 | void run_threads(void (*)(void *), void *); | ||
31 | |||
32 | static pthread_rwlock_t start; | ||
33 | static void (*real_func)(void *); | ||
34 | |||
35 | static void * | ||
36 | thread(void *arg) | ||
37 | { | ||
38 | int r; | ||
39 | |||
40 | if ((r = pthread_rwlock_rdlock(&start))) | ||
41 | errc(1, r, "could not obtain lock in thread"); | ||
42 | real_func(arg); | ||
43 | if ((r = pthread_rwlock_unlock(&start))) | ||
44 | errc(1, r, "could not release lock in thread"); | ||
45 | return NULL; | ||
46 | } | ||
47 | |||
48 | void | ||
49 | run_threads(void (*func)(void *), void *arg) | ||
50 | { | ||
51 | pthread_t self, pthread[THREAD_COUNT]; | ||
52 | int i, r; | ||
53 | |||
54 | self = pthread_self(); | ||
55 | real_func = func; | ||
56 | if ((r = pthread_rwlock_init(&start, NULL))) | ||
57 | errc(1, r, "could not initialize lock"); | ||
58 | |||
59 | if ((r = pthread_rwlock_wrlock(&start))) /* block */ | ||
60 | errc(1, r, "could not lock lock"); | ||
61 | |||
62 | for (i = 0; i < THREAD_COUNT; i++) | ||
63 | if ((r = pthread_create(&pthread[i], NULL, thread, arg))) { | ||
64 | warnc(r, "could not create thread"); | ||
65 | pthread[i] = self; | ||
66 | } | ||
67 | |||
68 | |||
69 | if ((r = pthread_rwlock_unlock(&start))) /* unleash */ | ||
70 | errc(1, r, "could not release lock"); | ||
71 | |||
72 | sleep(1); | ||
73 | |||
74 | if ((r = pthread_rwlock_wrlock(&start))) /* sync */ | ||
75 | errx(1, "parent could not sync with children: %s", | ||
76 | strerror(r)); | ||
77 | |||
78 | for (i = 0; i < THREAD_COUNT; i++) | ||
79 | if (! pthread_equal(pthread[i], self) && | ||
80 | (r = pthread_join(pthread[i], NULL))) | ||
81 | warnc(r, "could not join thread"); | ||
82 | } | ||
83 | |||