This is a multi-part message in MIME format. --------------020904020209090002050207 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suraj N. Kurapati wrote: > Nobuyoshi Nakada wrote: >> Your example does create new thread outside of ruby, the >> interpreter doesn't know about the thread. You should use >> rb_thread_create() instead. > > I tried your suggestion, but it did not work very well for me (see > below). Perhaps I wrote a poor implementation? I tried a different implementation (see attached tarball) this time, using the Queue class for thread synchronization. The example now works in Ruby 1.8.6, but not in 1.9.0 (see below). Why does this example fail with Ruby 1.9.0 ? Thanks for your consideration. ##### With Ruby 1.8.6 ##### $ sh make.sh ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux] checking for ruby_init() in -lruby... no checking for ruby_init() in -lruby-static... no creating Makefile /usr/lib/ruby/1.8/mkmf.rb:1110: warning: global variable `$preload' not initialized cc -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I. -fPIC -fno-strict-aliasing -g -O2 -fPIC -c main.c cc -o main.so main.o -L"." -L"/usr/lib" -L. -rdynamic -Wl,-export-dynamic -lruby1.8 -lpthread -ldl -lcrypt -lm -lc C: RUBY_INIT_STACK C: ruby_init() C: ruby_init_loadpath() C: rb_thread_create() R: BEGIN (ad-hoc from rb_thread_create()) R: wait for C C: relay to Ruby -- begin C: wake up Ruby R: BEGIN (synchronized with C) R: {:current <Thread:0xb7c5f3e8 run>, :main <Thread:0xb7c6c700 run>} ./hello.rb: delay 1 C: wait for Ruby ./hello.rb: delay 2 ./hello.rb: delay 3 R: relay to C -- begin R: wake up C C: relay to Ruby -- end C: relay to Ruby -- begin C: wake up Ruby R: wait for C R: relay to C -- end R: wake up C R: END C: wait for Ruby C: relay to Ruby -- end C: Thread.list [#<Thread:0xb7c6c700 run>] C: ruby_finalize() C: exit ##### With Ruby 1.9.0 ##### $ sh make.sh ruby 1.9.0 (2007-12-25 revision 14709) [i686-linux] /home/sun/app/ruby19/lib/ruby/1.9.0/mkmf.rb:1082: warning: empty expression /home/sun/app/ruby19/lib/ruby/1.9.0/mkmf.rb:1120: warning: empty expression checking for ruby_init() in -lruby... no checking for ruby_init() in -lruby-static... yes creating Makefile gcc -I. -I/home/sun/app/ruby19/include/ruby-1.9.0/i686-linux -I/home/sun/app/ruby19/include/ruby-1.9.0 -I. -D_FILE_OFFSET_BITSd -fPIC -g -O2 -o main.o -c main.c gcc -o main.so main.o -L. -L/home/sun/app/ruby19/lib -Wl,-R/home/sun/app/ruby19/lib -L. -rdynamic -Wl,-export-dynamic -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc C: RUBY_INIT_STACK C: ruby_init() C: ruby_init_loadpath() C: rb_thread_create() C: relay to Ruby -- begin C: wake up Ruby <dummy toplevel>:17: [BUG] Segmentation fault ruby 1.9.0 (2007-12-25 revision 14709) [i686-linux] -- control frame ---------- c:0001 p:0000 s:0002 b:0002 l:000001 d:000001 TOP <dummy toplevel>:17 --------------------------- -- backtrace of native function call (Use addr2line) -- 0x80f7b0a 0x8115a0c 0x8115a7b 0x80c8b60 0xffffe440 0xb7f85cc4 0x80f559e 0x80f6994 0x805db38 0x805de30 0x805e1a5 0x805aa00 0x805ab55 0x805abc7 0xb7de5050 0x805a7d1 ------------------------------------------------------- Aborted (core dumped) ##### Stack trace of the Ruby 1.9.0 run ##### $ gdb -c core ./main.so GNU gdb 6.6-debian Copyright (C) 2006 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 "i486-linux-gnu"... Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1". warning: exec file is newer than core file. warning: Can't read pathname for load map: Input/output error. Reading symbols from /lib/tls/i686/cmov/libpthread.so.0...done. Loaded symbols for /lib/tls/i686/cmov/libpthread.so.0 Reading symbols from /lib/tls/i686/cmov/librt.so.1...done. Loaded symbols for /lib/tls/i686/cmov/librt.so.1 Reading symbols from /lib/tls/i686/cmov/libdl.so.2...done. Loaded symbols for /lib/tls/i686/cmov/libdl.so.2 Reading symbols from /lib/tls/i686/cmov/libcrypt.so.1...done. Loaded symbols for /lib/tls/i686/cmov/libcrypt.so.1 Reading symbols from /lib/tls/i686/cmov/libm.so.6...done. Loaded symbols for /lib/tls/i686/cmov/libm.so.6 Reading symbols from /lib/tls/i686/cmov/libc.so.6...done. Loaded symbols for /lib/tls/i686/cmov/libc.so.6 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2 Reading symbols from /lib/libgcc_s.so.1...done. Loaded symbols for /lib/libgcc_s.so.1 Core was generated by `./main.so'. Program terminated with signal 6, Aborted. #0 0xffffe410 in __kernel_vsyscall () (gdb) bt #0 0xffffe410 in __kernel_vsyscall () #1 0xb7df9875 in raise () from /lib/tls/i686/cmov/libc.so.6 #2 0xb7dfb201 in abort () from /lib/tls/i686/cmov/libc.so.6 #3 0x08115a80 in rb_compile_bug ( file 813b6b1 "Â\023\b¤Â\023\bôÂ\023\b(®\023\bx®\023\bÄ®\023\bø®\023\b(¯\023\bp¯\023\b´¯\023\bø¯\023\bD°\023\b\210°\023\b°°\023\bð°\023\b$±\023\bp±\023\b¡Þ\023\b¡Þ\023\b\f\023\b", line fmt 2348 <Address 0x2348 out of bounds>) at error.c:239 #4 0x080c8b60 in sigsegv (sig) at signal.c:534 #5 <signal handler called> #6 0xb7df967c in siglongjmp () from /lib/tls/i686/cmov/libc.so.6 #7 0xb7f85cc4 in siglongjmp () from /lib/tls/i686/cmov/libpthread.so.0 #8 0x080f559e in vm_eval_body (th 8170160) at vm.c:1326 #9 0x080f6994 in vm_call0 (th 8170160, klass084007260, recv084005960, id2, oidD08, argc argv bfe1d410, body b7d236d0, nosuper at vm_insnhelper.c:45 #10 0x0805db38 in rb_call0 (klass084007260, recv084005960, mid2, argc argv bfe1d410, scope0 self@ at eval.c:1405 #11 0x0805de30 in rb_f_send (argc argv bfe1d410, recv0 at eval.c:1504 #12 0x0805e1a5 in rb_funcall (recv alue optimized out>, mid2, n at ./include/ruby/ruby.h:896 #13 0x0805aa00 in relay_to_c () at main.c:68 #14 0x0805ab55 in the_c_program () at main.c:120 #15 0x0805abc7 in the_c_program () at main.c:132 #16 0xb7de5050 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6 #17 0x0805a7d1 in _start () (gdb) bt full #0 0xffffe410 in __kernel_vsyscall () No symbol table info available. #1 0xb7df9875 in raise () from /lib/tls/i686/cmov/libc.so.6 No symbol table info available. #2 0xb7dfb201 in abort () from /lib/tls/i686/cmov/libc.so.6 No symbol table info available. #3 0x08115a80 in rb_compile_bug ( file 813b6b1 "\023\b\023\b\023\b(\023\bx\023\b\023\b\023\b(¡±\023\bp¡±\023\b¡¡±\023\b¡±\023\bD¡ë\023\b\210¡ë\023\b¡ë¡ë\023\b¡ë\023\b$¡Þ\023\bp¡Þ\023\b¡Þ\023\b¡Þ\023\b\f\023\b", line fmt 2348 <Address 0x2348 out of bounds>) at error.c:239 args x6 <Address 0x6 out of bounds> #4 0x080c8b60 in sigsegv (sig) at signal.c:534 No locals. #5 <signal handler called> No symbol table info available. #6 0xb7df967c in siglongjmp () from /lib/tls/i686/cmov/libc.so.6 No symbol table info available. #7 0xb7f85cc4 in siglongjmp () from /lib/tls/i686/cmov/libpthread.so.0 No symbol table info available. #8 0x080f559e in vm_eval_body (th 8170160) at vm.c:1326 i value optimized out> catch_iseqval escape_dfp VALUE *) 0x0 type 219247740 epc cont_pc value optimized out> cont_sp value optimized out> _tag buf {__jmpbuf -1210269800, -1210961336, -1210793956, -1075719400, -677101439, 178833390}, __mask_was_saved , __saved_mask {__val 3086671808, 3219247824, 3086420848, 3219247876, 3086671808, 3086729148, 3219247808, 3219248036, 2090266759, 8, 3084725324, 3084725276, 3773176208, 2090266758, 3086462264, 3086461704, 0, 0, 1, 2229, 3086421456, 3086419976, 3086467711, 3084761180, 3219247976, 3084173340, 135725408, 135057177, 0, 3219248052, 3086672230, 3084007260}}}}, tag , retval 219247928, prev x0} state result value optimized out> err 084005720 #9 0x080f6994 in vm_call0 (th 8170160, klass084007260, recv084005960, id2, oidD08, argc argv bfe1d410, body b7d236d0, nosuper at vm_insnhelper.c:45 i value optimized out> val value optimized out> blockptr value optimized out> #10 0x0805db38 in rb_call0 (klass084007260, recv084005960, mid2, argc argv bfe1d410, scope0 self@ at eval.c:1405 body NODE *) 0xb7d236d0 method value optimized out> noex id 408 ent struct cache_entry *) 0x0 th rb_thread_t *) 0x8170160 #11 0x0805de30 in rb_f_send (argc argv bfe1d410, recv0 at eval.c:1504 No locals. #12 0x0805e1a5 in rb_funcall (recv alue optimized out>, mid2, n at ./include/ruby/ruby.h:896 argv VALUE *) 0xbfe1d410 ar xbfe1d470 "\005\b4\025\b¡¯U\005\b¡¯\005\b" ---Type <return> to continue, or q <return> to quit--- #13 0x0805aa00 in relay_to_c () at main.c:68 No locals. #14 0x0805ab55 in the_c_program () at main.c:120 variable_in_this_stack_frame 34589034 cQueue 35655732 #15 0x0805abc7 in the_c_program () at main.c:132 variable_in_this_stack_frame 34589383 cQueue 219248336 #16 0xb7de5050 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6 No symbol table info available. #17 0x0805a7d1 in _start () No symbol table info available. (gdb) --------------020904020209090002050207 Content-Type: application/x-gzip; name