diff options
| author | cvs2svn <admin@example.com> | 2025-08-02 06:16:35 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2025-08-02 06:16:35 +0000 |
| commit | a397c95f8aea58533e72379d6e0de12683ecd0dc (patch) | |
| tree | 45ccaccd0ce2ea01650f0a9f5e9268a656e17e51 /src/regress/lib/libc/stdio_threading/include | |
| parent | a79e90e7342954ae2287db505811ca3c1cd336d7 (diff) | |
| download | openbsd-tb_20250802.tar.gz openbsd-tb_20250802.tar.bz2 openbsd-tb_20250802.zip | |
This commit was manufactured by cvs2git to create tag 'tb_20250802'.tb_20250802
Diffstat (limited to 'src/regress/lib/libc/stdio_threading/include')
| -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 | |||
