Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Thread.current.parent and Thread.current.ancestors
Ara.T.Howard
2/16/2007 6:56:00 AM
3 Answers
Erik Veenstra
2/16/2007 9:06:00 AM
0
It doesn't work with Thread#start (==fork)...
Thread#start doesn't reuse Thread.new. Neither does
rb_thread_create(), which is used in e.g. TK.
All three methods (new, start/fork and rb_thread_create()) come
together in rb_thread_alloc(). That's the place where the
parent should be set. The problem is that you can't redefine
rb_thread_alloc() in Ruby... ;[
I really like this Thread.current.parent or Thread.parent.
There's at least one place where I really, really need it
myself... Something for Ruby 1.8.6?... ;]
gegroet,
Erik V. -
http://www.erikve...
Erik Veenstra
2/16/2007 9:32:00 AM
0
Using new_with_parent (see below) has two advantages:
* By calling new_with_parent, you're saying: Yes, I know that
parent doesn't work for all threads.
* Thread#parent doesn't return nil for "unpatched" threads,
since it doesn't exist in the first place.
You can achieve the same by subclassing Thread.
Disadvantage:
* You can only ask for parents of your own threads. You can't
ask for a parent of e.g. a DRb thread, since those aren't
patched.
gegroet,
Erik V. -
http://www.erikve...
----------------------------------------------------------------
class Thread
def self.new_with_parent(*args, &block)
parent = Thread.current
self.new do
define_method :parent do
parent
end
block.call(*args)
end
end
end
----------------------------------------------------------------
Ara.T.Howard
2/16/2007 3:34:00 PM
0
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Thread.current.parent and Thread.current.ancestors
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password