From: Brent Roman Date: 2009-03-10T04:31:05+09:00 Subject: [ruby-core:22786] [Feature #1257] Add Continuation#thread method Feature #1257: Add Continuation#thread method http://redmine.ruby-lang.org/issues/show/1257 Author: Brent Roman Status: Open, Priority: Normal Please respond to this (redmine) post rather than [ruby-core:22772] --- This proposal is to add the method Continuation#thread that returns the thread that would be continued on Continuation#call. It would return nil if the thread on which the continuation had been created had died in the meantime. Continuation#thread would be provided in all Ruby implementations that support Continuation objects. Motivation: Every Continuation object must contain a reference to the thread that will be continued if it is called. However, there currently exists no method to return that thread. There is no generic way to determine it without the unpredictable side effects associated with calling the continuation. Example Implementation: The method is currently available for v1.8.* in the MBARI patches available at: http://sites.google.com/site/brentsrubypatches/ Here's an implementation with documentation for Continue#thread excerpted from that patched eval.c: /* * call-seq: * cont.thread * * Returns the thread on which this continuation can be called * or nil if that thread has died * * t = Thread.new {callcc{|c| $x=c}; sleep 5} * sleep 1 * $x.thread #=> t * sleep 10 * $x.thread #=> nil * */ static VALUE rb_cont_thread(cont) VALUE cont; { rb_thread_t th = THREAD_DATA(cont); cc_purge(th); /* frees th's stack and nils th->thread if th is dead */ return th->thread; } ---------------------------------------- http://redmine.ruby-lang.org