Skip to content

Commit 1858233

Browse files
committed
Free the native thread of the main thread on FREE_AT_EXIT
1 parent 8eb28da commit 1858233

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

internal/thread.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ void rb_thread_io_close_wait(struct rb_io *);
6464

6565
void rb_ec_check_ints(struct rb_execution_context_struct *ec);
6666

67+
void rb_thread_free_native_thread(void *th_ptr);
68+
6769
RUBY_SYMBOL_EXPORT_BEGIN
6870

6971
void *rb_thread_prevent_fork(void *(*func)(void *), void *data); /* for ext/socket/raddrinfo.c */

thread.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,15 @@ thread_cleanup_func(void *th_ptr, int atfork)
529529
rb_native_mutex_destroy(&th->interrupt_lock);
530530
}
531531

532+
void
533+
rb_thread_free_native_thread(void *th_ptr)
534+
{
535+
rb_thread_t *th = th_ptr;
536+
537+
native_thread_destroy_atfork(th->nt);
538+
th->nt = NULL;
539+
}
540+
532541
static VALUE rb_threadptr_raise(rb_thread_t *, int, VALUE *);
533542
static VALUE rb_thread_to_s(VALUE thread);
534543

vm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,8 +3306,7 @@ ruby_vm_destruct(rb_vm_t *vm)
33063306
rb_id_table_free(vm->constant_cache);
33073307
set_free_table(vm->unused_block_warning_table);
33083308

3309-
xfree(th->nt);
3310-
th->nt = NULL;
3309+
rb_thread_free_native_thread(th);
33113310

33123311
#ifndef HAVE_SETPROCTITLE
33133312
ruby_free_proctitle();

0 commit comments

Comments
 (0)