aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-10-13 01:14:17 +0900
committerKoichi Sasada <ko1@atdot.net>2023-10-13 09:19:31 +0900
commitcdb36dfe7ddb7cbd7ed95e84b24114c8869a7e5e (patch)
tree2de31772f8288869838c7fa5fff6ba60c342453f /thread.c
parent2794a8fef65eb16767c2f46f8f5058c10b4591b9 (diff)
downloadruby-cdb36dfe7ddb7cbd7ed95e84b24114c8869a7e5e.tar.gz
fix `native_thread_destroy()` timing
With M:N thread scheduler, the native thread (NT) related resources should be freed when the NT is no longer needed. So the calling `native_thread_destroy()` at the end of `is will be freed when `thread_cleanup_func()` (at the end of Ruby thread) is not correct timing. Call it when the corresponding Ruby thread is collected.
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/thread.c b/thread.c
index d59e3d8773..71e33b164a 100644
--- a/thread.c
+++ b/thread.c
@@ -508,16 +508,13 @@ thread_cleanup_func(void *th_ptr, int atfork)
* Unfortunately, we can't release native threading resource at fork
* because libc may have unstable locking state therefore touching
* a threading resource may cause a deadlock.
- *
- * FIXME: Skipping native_mutex_destroy(pthread_mutex_destroy) is safe
- * with NPTL, but native_thread_destroy calls pthread_cond_destroy
- * which calls free(3), so there is a small memory leak atfork, here.
*/
- if (atfork)
+ if (atfork) {
+ th->nt = NULL;
return;
+ }
rb_native_mutex_destroy(&th->interrupt_lock);
- native_thread_destroy(th);
}
static VALUE rb_threadptr_raise(rb_thread_t *, int, VALUE *);