diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-07-28 19:55:55 +1200 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2021-09-26 20:49:54 +0900 |
commit | 8ac058b64577d9b6fb1ee998d0fa7800529d7d34 (patch) | |
tree | 840566542980745ab96d859b503671ea368062e1 /vm.c | |
parent | 7d4a0c4b93cbdf40a9a43c4974199405099a8545 (diff) |
Fix potential hang when joining threads.
If the thread termination invokes user code after `th->status` becomes
`THREAD_KILLED`, and the user unblock function causes that `th->status` to
become something else (e.g. `THREAD_RUNNING`), threads waiting in
`thread_join_sleep` will hang forever. We move the unblock function call
to before the thread status is updated, and allow threads to join as soon
as `th->value` becomes defined.
This reverts commit 6505c77501f1924571b2fe620c5c7b31ede0cd22.
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -3083,6 +3083,8 @@ th_init(rb_thread_t *th, VALUE self) th->thread_id_string[0] = '\0'; #endif + th->value = Qundef; + #if OPT_CALL_THREADED_CODE th->retval = Qundef; #endif @@ -3095,16 +3097,17 @@ static VALUE ruby_thread_init(VALUE self) { rb_thread_t *th = GET_THREAD(); - rb_thread_t *targe_th = rb_thread_ptr(self); + rb_thread_t *target_th = rb_thread_ptr(self); rb_vm_t *vm = th->vm; - targe_th->vm = vm; - th_init(targe_th, self); + target_th->vm = vm; + th_init(target_th, self); + + target_th->top_wrapper = 0; + target_th->top_self = rb_vm_top_self(); + target_th->ec->root_svar = Qfalse; + target_th->ractor = th->ractor; - targe_th->top_wrapper = 0; - targe_th->top_self = rb_vm_top_self(); - targe_th->ec->root_svar = Qfalse; - targe_th->ractor = th->ractor; return self; } |