mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
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.
This commit is contained in:
parent
2794a8fef6
commit
cdb36dfe7d
4 changed files with 26 additions and 32 deletions
|
@ -623,11 +623,13 @@ native_thread_init_stack(rb_thread_t *th)
|
|||
(void *)InterlockedExchange((long *)(t), (long)(v))
|
||||
#endif
|
||||
static void
|
||||
native_thread_destroy(rb_thread_t *th)
|
||||
native_thread_destroy(struct rb_native_thread *nt)
|
||||
{
|
||||
HANDLE intr = InterlockedExchangePointer(&th->nt->interrupt_event, 0);
|
||||
RUBY_DEBUG_LOG("close handle intr:%p, thid:%p\n", intr, th->nt->thread_id);
|
||||
w32_close_handle(intr);
|
||||
if (nt) {
|
||||
HANDLE intr = InterlockedExchangePointer(&nt->interrupt_event, 0);
|
||||
RUBY_DEBUG_LOG("close handle intr:%p, thid:%p\n", intr, nt->thread_id);
|
||||
w32_close_handle(intr);
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned long __stdcall
|
||||
|
@ -893,6 +895,7 @@ th_has_dedicated_nt(const rb_thread_t *th)
|
|||
void
|
||||
rb_threadptr_sched_free(rb_thread_t *th)
|
||||
{
|
||||
native_thread_destroy(th->nt);
|
||||
ruby_xfree(th->nt);
|
||||
ruby_xfree(th->sched.vm_stack);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue