|
From: kosmirror <kos...@us...> - 2025-11-18 20:01:33
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "A pseudo Operating System for the Dreamcast.".
The branch, master has been updated
via 7ffb61cf845bf2e470f1baa47531937f1a447c95 (commit)
from de597f67ecd691074c2b843b14db6a2cb2132a66 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7ffb61cf845bf2e470f1baa47531937f1a447c95
Author: QuzarDC <qu...@co...>
Date: Sat Nov 15 13:43:16 2025 -0500
examples: Prevent race condition in reentrant mutex thread labels.
Before the output would print `Hello from thread unnamed!` if it
happened to be that the thread routine ran before the call to
set the thread label. By having that be passed in on thread creation
the label is guaranteed to always be present at the time of that print.
-----------------------------------------------------------------------
Summary of changes:
.../basic/threading/reentrant_mutex/reentrant_mutex.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/examples/dreamcast/basic/threading/reentrant_mutex/reentrant_mutex.c b/examples/dreamcast/basic/threading/reentrant_mutex/reentrant_mutex.c
index 29a3d93f..32d9d1b7 100644
--- a/examples/dreamcast/basic/threading/reentrant_mutex/reentrant_mutex.c
+++ b/examples/dreamcast/basic/threading/reentrant_mutex/reentrant_mutex.c
@@ -168,6 +168,9 @@ static void *thread_func(void *arg) {
int main(int argc, const char* argv[]) {
kthread_t *threads[THREAD_COUNT];
+
+ char thd_label[16];
+ kthread_attr_t attrs = { .label = thd_label };
/* Initialize our mutex */
reentrant_mutex_init(&rmutex);
@@ -175,12 +178,10 @@ int main(int argc, const char* argv[]) {
/* Spawn a bunch of threads, potentially yielding the main thread after
each one gets spawned. */
for(size_t i = 0; i < THREAD_COUNT; ++i) {
- threads[i] = thd_create(false, thread_func, NULL);
-
- char thd_label[16];
snprintf(thd_label, sizeof(thd_label), "%u", i);
- thd_set_label(threads[i], thd_label);
-
+
+ threads[i] = thd_create_ex(&attrs, thread_func, NULL);
+
maybe_pass();
}
hooks/post-receive
--
A pseudo Operating System for the Dreamcast.
|