[MacRuby] #794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22)
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- I atach the Test Script of Ruby 1.9.2 RC2. An Error occurs when executed "test_require.rb": {{{ $ macruby test_require.rb Loaded suite test_require Started pthread command `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) zsh: abort macruby test_require.rb }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/794> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): Looks like it's related to thread cancelation. This is an area we are currently looking at (in order to fix similar bugs you filed with threads). Regarding crash traces, if you can, it's better to run your test using the version of MacRuby in the build directory instead of the one that has been installed. This way, it has full debugging symbols. I generally do it like this: $ DYLD_LIBRARY_PATH=. ./macruby -I./lib foo.rb. -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:1> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): The stack trace was as follows: {{{ $ DYLD_LIBRARY_PATH=. gdb --args ./macruby -I./lib test_require.rb GNU gdb 6.3.50-20050815 (Apple version gdb-1461.2) (Fri Mar 5 04:43:10 UTC 2010) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ..... done (gdb) r Starting program: /Users/watson/src/MacRuby/macruby -I./lib test_require.rb Reading symbols for shared libraries .++++.......................... done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Loaded suite test_require Started Reading symbols for shared libraries . done pthread command `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) Program received signal SIGABRT, Aborted. 0x00007fff815783d6 in __kill () (gdb) thread apply all bt Thread 2 (process 49329): #0 0x00007fff8154308a in kevent () #1 0x00007fff81544f5d in _dispatch_mgr_invoke () #2 0x00007fff81544c34 in _dispatch_queue_invoke () #3 0x00007fff8154475e in _dispatch_worker_thread2 () #4 0x00007fff81544088 in _pthread_wqthread () #5 0x00007fff81543f25 in start_wqthread () Thread 1 (process 49329): #0 0x00007fff815783d6 in __kill () #1 0x00007fff81618972 in abort () #2 0x0000000100147594 in rb_vm_thread_cancel (t=0x2002a02e0) at vm.cpp:4598 #3 0x00000001000ea3fe in rb_thread_kill (thread=8592527328, sel=0x6) at thread.c:332 #4 0x00000001001402d6 in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x1017222c0, top=8592524704, self=8592527328, klass=0x2000aef20, sel=0x103637f80, block=0x0, opt=0 '\0', argc=<value temporarily unavailable, due to optimizations>, argv=0x0) at dispatcher.cpp:159 #5 0x0000000104400a20 in ?? () #6 0x0000000104439e36 in ?? () #7 0x000000010014020b in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x101742540, top=8592715200, self=8592524704, klass=0x200278560, sel=0x1052dfdb0, block=0x0, opt=0 '\0', argc=<value temporarily unavailable, due to optimizations>, argv=0x7fff5fbf7a50) at dispatcher.cpp:170 #8 0x0000000104400a20 in ?? () #9 0x0000000104441ddb in ?? () #10 0x00000001001401cd in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x10171b0c0, top=8592715200, self=8592715200, klass=0x2002a62a0, sel=0x10406bc50, block=0x0, opt=2 '\002', argc=<value temporarily unavailable, due to optimizations>, argv=0x7fff5fbf7c10) at dispatcher.cpp:173 #11 0x0000000104400a20 in ?? () #12 0x0000000104441926 in ?? () #13 0x00000001001402d6 in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x1017324c0, top=0, self=8592715200, klass=0x2002a62a0, sel=0x10408cb90, block=0x0, opt=2 '\002', argc=<value temporarily unavailable, due to optimizations>, argv=0x7fff5fbf9f88) at dispatcher.cpp:159 #14 0x00000001000ff340 in rb_f_send (recv=8592715200, sel=<value temporarily unavailable, due to optimizations>, argc=<value temporarily unavailable, due to optimizations>, argv=0x7fff5fbf9f80) at vm.h:594 #15 0x0000000100140379 in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x101733fc0, top=8592715200, self=8592715200, klass=0x2002a62a0, sel=0x10155d400, block=0x0, opt=0 '\0', argc=1, argv=0x7fff5fbf9f80) at dispatcher.cpp:435 #16 0x0000000104400a20 in ?? () #17 0x0000000104440825 in ?? () #18 0x00000001001402bb in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x101743050, top=8592653344, self=8592715200, klass=0x2002a62a0, sel=0x1010d1103, block=0x0, opt=0 '\0', argc=<value temporarily unavailable, due to optimizations>, argv=0x7fff5fbfad10) at dispatcher.cpp:161 #19 0x0000000104400a20 in ?? () #20 0x000000010443ff37 in ?? () #21 0x0000000100142e87 in rb_vm_yield_args (_vm=0x10151e4f0, argc=<value temporarily unavailable, due to optimizations>, argv=0x2002a62a0) at dispatcher.cpp:100 #22 0x00000001000fd028 in rb_yield (val=8592430496) at vm_eval.c:196 #23 0x0000000100014ecd in rary_each (ary=8592742528, sel=<value temporarily unavailable, due to optimizations>) at array.c:1064 #24 0x00000001001402d6 in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x101747ac0, top=8592653344, self=8592742528, klass=0x20006d8a0, sel=0x1015415f0, block=0x2002ab520, opt=0 '\0', argc=<value temporarily unavailable, due to optimizations>, argv=0x0) at dispatcher.cpp:159 #25 0x0000000104400a20 in ?? () #26 0x000000010443f42f in ?? () #27 0x0000000100142e87 in rb_vm_yield_args (_vm=0x10151e4f0, argc=<value temporarily unavailable, due to optimizations>, argv=0x20006d8a0) at dispatcher.cpp:100 #28 0x00000001000fd028 in rb_yield (val=8592712352) at vm_eval.c:196 #29 0x0000000100014ecd in rary_each (ary=8592736672, sel=<value temporarily unavailable, due to optimizations>) at array.c:1064 #30 0x00000001001402d6 in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x101747ac0, top=8592653344, self=8592736672, klass=0x20006d8a0, sel=0x1015415f0, block=0x2002ad600, opt=0 '\0', argc=<value temporarily unavailable, due to optimizations>, argv=0x0) at dispatcher.cpp:159 #31 0x0000000104400a20 in ?? () #32 0x000000010443ec17 in ?? () #33 0x00000001001402bb in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x101731b00, top=8592653344, self=8592653344, klass=0x200241680, sel=0x10461a540, block=0x0, opt=2 '\002', argc=<value temporarily unavailable, due to optimizations>, argv=0x7fff5fbfdec8) at dispatcher.cpp:161 #34 0x0000000104400a20 in ?? () #35 0x000000010443ca45 in ?? () #36 0x00000001001402bb in rb_vm_dispatch (_vm=0x10151e4f0, cache=0x101726790, top=8592299648, self=8592653344, klass=0x200241680, sel=0x1010d1103, block=0x0, opt=0 '\0', argc=<value temporarily unavailable, due to optimizations>, argv=0x7fff5fbfec30) at dispatcher.cpp:161 #37 0x0000000104400a20 in ?? () #38 0x000000010441a941 in ?? () #39 0x0000000100141c79 in rb_vm_block_eval (b=0x10151e4f0, argc=<value temporarily unavailable, due to optimizations>, argv=0x1) at dispatcher.cpp:98 #40 0x0000000100150c1a in rb_rescue2 (b_proc=<value temporarily unavailable, due to optimizations>, data1=<value temporarily unavailable, due to optimizations>, r_proc=0x10003f7c0 <rb_end_proc_call_catch>, data2=0) at vm.cpp:3363 #41 0x000000010003fd90 in rb_exec_end_proc [inlined] () at /Users/watson/src/MacRuby/eval_jump.c:483 #42 ruby_finalize_0 [inlined] () at /Users/watson/src/MacRuby/eval.c:83 #43 0x000000010003fd90 in ruby_finalize () at eval_jump.c:97 #44 0x000000010009fc40 in rb_exit (status=0) at process.c:2473 #45 0x0000000100000d2f in main (argc=3, argv=0x10151de60, envp=<value temporarily unavailable, due to optimizations>) at main.cpp:40 (gdb) quit The program is running. Exit anyway? (y or n) y }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:2> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): The stack trace was as follows when I compiled with "rake optz_level=0" for MacRuby. {{{ $ DYLD_LIBRARY_PATH=. gdb --args ./macruby -I./lib test_require.rb GNU gdb 6.3.50-20050815 (Apple version gdb-1461.2) (Fri Mar 5 04:43:10 UTC 2010) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ..... done (gdb) r Starting program: /Users/watson/src/MacRuby/macruby -I./lib test_require.rb Reading symbols for shared libraries .++++.......................... done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries warning: .o file "/Users/watson/src/MacRuby/ext/etc/etc.o" more recent than executable timestamp in "/Library/Frameworks/MacRuby.framework/Versions/0.7/usr/lib/ruby/site_ruby/1.9.2 /universal-darwin10.0/etc.bundle" warning: Could not open OSO file /Users/watson/src/MacRuby/ext/etc/etc.o to scan for pubtypes for objfile /Library/Frameworks/MacRuby.framework/Versions/0.7/usr/lib/ruby/site_ruby/1.9.2 /universal-darwin10.0/etc.bundle . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Loaded suite test_require Started Reading symbols for shared libraries warning: .o file "/Users/watson/src/MacRuby/ext/socket/socket.o" more recent than executable timestamp in "/Library/Frameworks/MacRuby.framework/Versions/0.7/usr/lib/ruby/site_ruby/1.9.2 /universal-darwin10.0/socket.bundle" warning: Could not open OSO file /Users/watson/src/MacRuby/ext/socket/socket.o to scan for pubtypes for objfile /Library/Frameworks/MacRuby.framework/Versions/0.7/usr/lib/ruby/site_ruby/1.9.2 /universal-darwin10.0/socket.bundle . done pthread command `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) Program received signal SIGABRT, Aborted. 0x00007fff815783d6 in __kill () (gdb) thread apply all bt Thread 2 (process 84759): #0 0x00007fff8154308a in kevent () #1 0x00007fff81544f5d in _dispatch_mgr_invoke () #2 0x00007fff81544c34 in _dispatch_queue_invoke () #3 0x00007fff8154475e in _dispatch_worker_thread2 () #4 0x00007fff81544088 in _pthread_wqthread () #5 0x00007fff81543f25 in start_wqthread () Thread 1 (process 84759): #0 0x00007fff815783d6 in __kill () #1 0x00007fff81618972 in abort () #2 0x000000010013b9c4 in rb_vm_thread_cancel (t=0x2002a24e0) at vm.cpp:4598 #3 0x00000001000c9efc in rb_thread_kill (thread=8592547008, sel=0x101937e40) at thread.c:332 #4 0x000000010012e980 in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:159 #5 0x000000010012e980 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #6 0x000000010012e980 in rb_vm_dispatch () at dispatcher.cpp:816 #7 0x0000000103d5aa20 in ?? () #8 0x0000000103d93e36 in ?? () #9 0x000000010012eb2c in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:170 #10 0x000000010012eb2c in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #11 0x000000010012eb2c in rb_vm_dispatch () at dispatcher.cpp:816 #12 0x0000000103d5aa20 in ?? () #13 0x0000000103d9bddb in ?? () #14 0x000000010012ebb4 in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:173 #15 0x000000010012ebb4 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #16 0x000000010012ebb4 in rb_vm_dispatch () at dispatcher.cpp:816 #17 0x0000000103d5aa20 in ?? () #18 0x0000000103d9b926 in ?? () #19 0x000000010012e980 in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:159 #20 0x000000010012e980 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #21 0x000000010012e980 in rb_vm_dispatch () at dispatcher.cpp:816 #22 0x00000001000e0e88 in rb_vm_call0 (vm=0x10161e500, top=0, self=8592095264, klass=0x2002b4920, sel=0x1019c8230, block=0x0, opt=2 '\002', argc=0, argv=0x7fff5fbf8eb8) at vm.h:595 #23 0x00000001000e1f59 in rb_vm_call2 (block=0x0, self=8592095264, klass=8592771360, sel=0x1019c8230, argc=0, argv=0x7fff5fbf8eb8) at vm.h:620 #24 0x00000001000e1ec0 in rb_call (recv=8592095264, mid=15672, argc=0, argv=0x7fff5fbf8eb8, scope=3, pass_current_block=true) at vm_eval.c:45 #25 0x00000001000e227a in send_internal (argc=0, argv=0x7fff5fbf8eb8, recv=8592095264, scope=3) at vm_eval.c:144 #26 0x00000001000e22a8 in rb_f_send (recv=8592095264, sel=0x10165d410, argc=1, argv=0x7fff5fbf8eb0) at vm_eval.c:168 #27 0x000000010012e381 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:435 #28 0x000000010012e381 in rb_vm_dispatch () at dispatcher.cpp:816 #29 0x0000000103d5aa20 in ?? () #30 0x0000000103d9a825 in ?? () #31 0x000000010012e9b2 in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:161 #32 0x000000010012e9b2 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #33 0x000000010012e9b2 in rb_vm_dispatch () at dispatcher.cpp:816 #34 0x0000000103d5aa20 in ?? () #35 0x0000000103d99f37 in ?? () #36 0x0000000100134c13 in __rb_vm_bcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:100 #37 0x0000000100134c13 in vm_block_eval [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:1162 #38 0x0000000100134c13 in rb_vm_yield_args () at dispatcher.cpp:1217 #39 0x00000001000e233e in rb_vm_yield (argc=1, argv=0x7fff5fbfa418) at vm.h:629 #40 0x00000001000e2311 in rb_yield (val=8590921920) at vm_eval.c:196 #41 0x0000000100016b87 in rary_each (ary=8590880704, sel=0x101641600) at array.c:1064 #42 0x000000010012e980 in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:159 #43 0x000000010012e980 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #44 0x000000010012e980 in rb_vm_dispatch () at dispatcher.cpp:816 #45 0x0000000103d5aa20 in ?? () #46 0x0000000103d9942f in ?? () #47 0x0000000100134c13 in __rb_vm_bcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:100 #48 0x0000000100134c13 in vm_block_eval [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:1162 #49 0x0000000100134c13 in rb_vm_yield_args () at dispatcher.cpp:1217 #50 0x00000001000e233e in rb_vm_yield (argc=1, argv=0x7fff5fbfb9a8) at vm.h:629 #51 0x00000001000e2311 in rb_yield (val=8592771360) at vm_eval.c:196 #52 0x0000000100016b87 in rary_each (ary=8592649632, sel=0x101641600) at array.c:1064 #53 0x000000010012e980 in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:159 #54 0x000000010012e980 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #55 0x000000010012e980 in rb_vm_dispatch () at dispatcher.cpp:816 #56 0x0000000103d5aa20 in ?? () #57 0x0000000103d98c17 in ?? () #58 0x000000010012e9b2 in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:161 #59 0x000000010012e9b2 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #60 0x000000010012e9b2 in rb_vm_dispatch () at dispatcher.cpp:816 #61 0x0000000103d5aa20 in ?? () #62 0x0000000103d96a45 in ?? () #63 0x000000010012e9b2 in __rb_vm_rcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:161 #64 0x000000010012e9b2 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:453 #65 0x000000010012e9b2 in rb_vm_dispatch () at dispatcher.cpp:816 #66 0x0000000103d5aa20 in ?? () #67 0x0000000103d74941 in ?? () #68 0x0000000100132baf in __rb_vm_bcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:98 #69 0x0000000100132baf in vm_block_eval [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:1162 #70 0x0000000100132baf in rb_vm_block_eval (b=0x2002775c0, argc=0, argv=0x0) at dispatcher.cpp:1169 #71 0x00000001000413b2 in proc_call (procval=8592489312, sel=0x0, argc=0, argv=0x0) at proc.c:434 #72 0x000000010004141c in rb_proc_call2 (self=8592489312, argc=0, argv=0x0) at proc.c:452 #73 0x0000000100037c8b in rb_end_proc_call_try (proc=8592489312) at eval_jump.c:46 #74 0x0000000100146db4 in rb_rescue2 (b_proc=0x100037c6c <rb_end_proc_call_try>, data1=8592489312, r_proc=0x100037c8d <rb_end_proc_call_catch>, data2=0) at vm.cpp:3363 #75 0x0000000100038442 in rb_rescue (b_proc=0x100037c6c <rb_end_proc_call_try>, data1=8592489312, r_proc=0x100037c8d <rb_end_proc_call_catch>, data2=0) at eval.c:483 #76 0x0000000100037d0b in rb_exec_end_proc () at eval_jump.c:64 #77 0x0000000100037e0c in ruby_finalize_0 () at eval.c:83 #78 0x0000000100037e27 in ruby_finalize () at eval.c:97 #79 0x000000010008ce51 in rb_exit (status=0) at process.c:2473 #80 0x0000000100000c1c in main (argc=3, argv=0x10161de70, envp=0x7fff5fbff1f8) at main.cpp:40 (gdb) quit The program is running. Exit anyway? (y or n) y }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:3> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): An error occurs when pthread_mutex_destroy() is executed in RoxorCore::unregister_thread() right before MacRuby execute pthread_mutex_lock() in rb_vm_thread_cancel().[[BR]] So, I guess that should not use pthread_assert() in rb_vm_thread_cancel(). I do not yet understand why MacRuby do such a operation. {{{ #!diff diff --git a/vm.cpp b/vm.cpp index 60e6db4..649f6d3 100644 --- a/vm.cpp +++ b/vm.cpp @@ -4580,7 +4580,10 @@ rb_vm_thread_cancel(rb_vm_thread_t *t) rb_vm_thread_throw_kill(); } else { - pthread_assert(pthread_mutex_lock(&t->sleep_mutex)); + int code = pthread_mutex_lock(&t->sleep_mutex); + if(code == EINVAL) { + return; + } if (t->in_cond_wait) { // We are trying to kill a thread which is currently waiting // for a condition variable (#sleep). Instead of canceling the @@ -4588,12 +4591,12 @@ rb_vm_thread_cancel(rb_vm_thread_t *t) // will autodestroy itself, to work around a stack unwinding // bug in the Mac OS X pthread implementation that messes our // C++ exception handlers. - pthread_assert(pthread_cond_signal(&t->sleep_cond)); + pthread_cond_signal(&t->sleep_cond); } else { - pthread_assert(pthread_cancel(t->thread)); + pthread_cancel(t->thread); } - pthread_assert(pthread_mutex_unlock(&t->sleep_mutex)); + pthread_mutex_unlock(&t->sleep_mutex); } } } }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:4> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): When writing MacRuby we prefer to check for error codes and wrap critical things that should never happy in assertions, to catch bugs early. Sometimes we assert too much. It is possible that in this case some of the assertions are not needed. -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:5> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): It is necessary for "t->status = THREAD_DEAD" to move to the top of RoxorCore::unregister_thread().[[BR]] The reason is because it becomes the error when pthread_mutex_lock() in rb_vm_thread_cancel() is executed between pthread_mutex_destroy() and "t->status = THREAD_DEAD". {{{ #!diff diff --git a/vm.cpp b/vm.cpp index 60e6db4..1f6dc86 100644 --- a/vm.cpp +++ b/vm.cpp @@ -4291,6 +4291,9 @@ RoxorCore::unregister_thread(VALUE thread) { RoxorCoreLock lock; + rb_vm_thread_t *t = GetThreadPtr(thread); + t->status = THREAD_DEAD; + // We do not call #delete because it might trigger #== in case it has been // overriden on the thread object, and therefore cause a deadlock if the // new method tries to acquire the RoxorCore GIL. @@ -4311,8 +4314,6 @@ RoxorCore::unregister_thread(VALUE thread) lock.unlock(); - rb_vm_thread_t *t = GetThreadPtr(thread); - const int code = pthread_mutex_destroy(&t->sleep_mutex); if (code == EBUSY) { // The mutex is already locked, which means we are being called from @@ -4333,8 +4334,6 @@ RoxorCore::unregister_thread(VALUE thread) t->vm = NULL; pthread_assert(pthread_setspecific(RoxorVM::vm_thread_key, NULL)); - - t->status = THREAD_DEAD; } static inline void }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:6> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): Please forget the change of #comment:4. :) -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:7> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.7 Component: MacRuby | Resolution: fixed Keywords: | ----------------------------------+----------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.7 Comment: Thank you very much for the patch :-) It has been merged in r4402. I verified that specs run as before and that the script you attached doesn't crash that way anymore (it now prints errors, but I guess it's another problem). -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:8> MacRuby <http://macruby.org/>
#794: `pthread_mutex_unlock(&t->sleep_mutex)' failed: Invalid argument (22) ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: reopened Priority: blocker | Milestone: MacRuby 0.7 Component: MacRuby | Resolution: Keywords: | ----------------------------------+----------------------------------------- Changes (by watson1978@…): * status: closed => reopened * resolution: fixed => Comment: Sorry. This issue reproduces as followin conditions: * pthread_mutex_destroy() is executed between "t->status = THREAD_KILLED" and pthread_mutex_lock() in rb_vm_thread_cancel(). * pthread_mutex_unlock() and pthread_mutex_destroy() in unregister_thread() were executed while executed pthread_mutex_lock() in rb_vm_thread_cancel(), assertion fails when executes pthread_mutex_unlock() in rb_vm_thread_cancel(). So, I think that should lock the GlobalLock for exclusive control of rb_vm_thread_cancel() and unregister_thread() while executes rb_vm_thread_cancel(). A change of comment:6 and below will be necessary. {{{ #!diff diff --git a/vm.cpp b/vm.cpp index 1edcb5d..01c9bab 100644 --- a/vm.cpp +++ b/vm.cpp @@ -4609,10 +4609,14 @@ extern "C" void rb_vm_thread_cancel(rb_vm_thread_t *t) { + RoxorCoreLock lock; + if (t->status != THREAD_KILLED && t->status != THREAD_DEAD) { t->status = THREAD_KILLED; if (t->thread == pthread_self()) { + lock.unlock(); rb_vm_thread_throw_kill(); + return; } else { pthread_assert(pthread_mutex_lock(&t->sleep_mutex)); @@ -4631,6 +4635,7 @@ rb_vm_thread_cancel(rb_vm_thread_t *t) pthread_assert(pthread_mutex_unlock(&t->sleep_mutex)); } } + lock.unlock(); } extern "C" }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/794#comment:9> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby