From: Yukihiro Matsumoto Date: 2010-12-16T07:46:34+09:00 Subject: [ruby-core:33740] Re: [Ruby 1.9-Feature#2294] [PATCH] ruby_bind_stack() to embed Ruby in coroutine Hi, In message "Re: [ruby-core:33730] Re: [Ruby 1.9-Feature#2294] [PATCH] ruby_bind_stack() to embed Ruby in coroutine" on Thu, 16 Dec 2010 02:48:07 +0900, SASADA Koichi writes: | |Hi, | |Suraj, I'm sorry for late response. I missed this thread. | |I read the last patch: |http://redmine.ruby-lang.org/attachments/download/1153 | |and I need to say "no". | |As nobu said at first, this patch is not considering the multi-threading. |(and using global variables should not be accepted :) The patch is too |ad-hoc modification) | | |I propose another API. | |idea 1: | |// API for C extension. |// User needs to know thread value. |rb_thread_set_stack(VALUE thread_val, upper, lower) { | th = thread_data(thread_val); | th->upper = upper; | th->lower = lower; |} | |idea 2: | |// API called from not a Ruby world |ruby_bind_stack_for_current_native_thread(upper, lower) { | th = thread_data_for_current_native_thread(); | | if (th == 0) { | // Current native thread does not have | // the related ruby thread. | return 0; | } | | th->upper = upper; | th->lower = lower; | return 1; |} | | |BTW, how to get the correct "upper"/"lower" address of stack? I am afraid that there's no portable and/or reliable way. Conservative GC does similar thing, maybe you can steal boundary values from it. matz.