From: "Suraj N. Kurapati" Date: 2006-04-17T08:40:21+09:00 Subject: Re: cross-thead violation - example code --------------050501040806020408020407 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Suraj N. Kurapati wrote: > {process: > pthread_create(); > ... > > {pthread: > ruby_init(); > ... > ruby_run(); > } > > ... > rb_ary_new(); // causes cross-thread violation on rb_gc() > } Attached with this e-mail is example code for the above scenario. If you un-comment the function-call to rb_ary_new() inside main(), then the cross-thread violation does not occur. Here is what happens when the scenario is compiled and run: $ gcc -Wall -g -I$(ruby -rmkmf -e 'puts $topdir') \ - -l$(ruby -rmkmf -e 'puts CONFIG["RUBY_SO_NAME"]') \ - -lpthread ctviol.c -o ctviol $ ./ctviol [BUG] cross-thread violation on rb_gc() ruby 1.8.4 (2005-12-24) [i486-linux] Aborted (core dumped) Here is the environment in which I ran the scenario: $ ruby -v ruby 1.8.4 (2005-12-24) [i486-linux] $ uname -a Linux yantram 2.6.15-20-386 #1 PREEMPT Tue Apr 4 17:48:51 UTC 2006 i686 GNU/Linux $ ulimit -a core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited max nice (-e) unlimited file size (blocks, -f) unlimited pending signals (-i) unlimited max locked memory (kbytes, -l) unlimited max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) unlimited max rt priority (-r) unlimited stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) unlimited virtual memory (kbytes, -v) unlimited file locks (-x) unlimited Thanks for your consideration. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFEQtXbmV9O7RYnKMcRApdxAJ47u24c1Y9pUNmmGhDQY1sXpVmjoQCgjdo7 QksRFhYmPV1Qb2b6/TDyHaw= =SIFP -----END PGP SIGNATURE----- --------------050501040806020408020407 Content-Type: text/x-csrc; name="ctviol.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ctviol.c" /* Generates a cross-thread violation on rb_gc() under ruby 1.8.4 (2005-12-24) [i486-linux] */ #include #include void* ruby_run_handshake(void* dummy) { ruby_init(); ruby_init_loadpath(); ruby_run(); // this never returns } int main(int argc, char** argv) { // run a Ruby interpreter in the background pthread_t rubyThread; pthread_create(&rubyThread, 0, ruby_run_handshake, 0); // create some Ruby objects rb_ary_new(); // causes cross-thread violation on rb_gc() return 0; } --------------050501040806020408020407--