Issue #7452 has been updated by authorNari (Narihiro Nakamura).


????????????????????????????????
??????????????????????????????????Ruby?????????????????????????????????rb_objspace_call_finalizer????freelist??追???????????????????????????????????

?gdb?????????????????
#0  add_slot_local_freelist (objspace=0x5555559ed8f0, p=0x555555a5be48) at gc.c:819
#1  0x00005555555c7f42 in finalize_list (objspace=0x5555559ed8f0, p=0x555555a5be48) at gc.c:1423
#2  0x00005555555c7fd5 in finalize_deferred (objspace=0x5555559ed8f0) at gc.c:1443
#3  0x00005555555c81ee in rb_objspace_call_finalizer (objspace=0x5555559ed8f0) at gc.c:1509
#4  0x00005555555c81a6 in rb_gc_call_finalizer_at_exit () at gc.c:1493
#5  0x00005555555b1b5a in ruby_finalize_1 () at eval.c:127
#6  0x00005555555b1dbb in ruby_cleanup (ex=0) at eval.c:193
#7  0x00005555555b20a7 in ruby_run_node (n=0x555555a581e8) at eval.c:307
#8  0x00005555555746b9 in main (argc=3, argv=0x7fffffffd248) at main.c:36

rb_objspace_call_finalizer()??????????ruby_vm_destruct?VM????????????????????????????????????????????????????????使??????????????????????free???????????????????????????????????????????????????
??????????????????????????話???????rb_objspace_call_finalizer()?????????触????????????????????????????????????????????????????????????????????????

??????ad-hoc???????????????????????????????????????????
https://gist.github.com/4160845
VM?????????????????????????????????????????????????????????常??????????????????????強????????????????????????????????????????????????????????????

??????????????????以???????????????????????????強????????????????????????????????????????????????????????????????????信??????????????
Ruby??????????????????詳??????????????伺????????????????????????????

diff --git a/gc.c b/gc.c
index 63869a0..8d68e38 100644
--- a/gc.c
+++ b/gc.c
@@ -1505,15 +1505,9 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
     if (ATOMIC_EXCHANGE(finalizing, 1)) return;
 
     /* run finalizers */
-    do {
-       finalize_deferred(objspace);
-       /* mark reachable objects from finalizers */
-       /* They might be not referred from any place here */
-       mark_tbl(objspace, finalizer_table);
-       gc_mark_stacked_objects(objspace);
-       st_foreach(finalizer_table, chain_finalized_object,
-                  (st_data_t)&deferred_final_list);
-    } while (deferred_final_list);
+    finalize_deferred(objspace);
+    assert(deferred_final_list == 0);
+
     /* force to run finalizer */
     while (finalizer_table->num_entries) {
        struct force_finalize_list *list = 0;

----------------------------------------
Bug #7452: Main thread is stopped after running finalizers if the main thread has a finalizer
https://bugs.ruby-lang.org/issues/7452#change-34081

Author: mrkn (Kenta Murata)
Status: Assigned
Priority: Normal
Assignee: authorNari (Narihiro Nakamura)
Category: core
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-11-28 trunk 37923) [x86_64-darwin11.4.2]


以??????????????????????????????????????????????????????????????????止?????????????????

   ObjectSpace.define_finalizer(Thread.main) {}

trunk ??? ruby_1_9_3 ???????????????????????????????確????????????????

trunk ??以???? gist ??貼???? patch ??修正?????????????
https://gist.github.com/4159481

1.9.3 ??以???? gist ??貼???? patch ??修正?????????????
https://gist.github.com/4159480


-- 
http://bugs.ruby-lang.org/