T
tony summerfelt
i see that a number of modules are declared 'thread safe?'
what does this mean as it applies to ruby?
what does this mean as it applies to ruby?
i see that a number of modules are declared 'thread safe?'
=20
what does this mean as it applies to ruby?
Adam said:I'd like to call a particular inherited method rather than the one in my
immediate ancestor. For instance
class Parent
def to_s
super.to_s + " Parent-specific stuff here."
end
end
class Child < Parent
def to_s
# I want to call Object.to_s here ...
object__to_s
end
end
I can't figure out the right syntax. Any hints? For what it's worth I'm
using Ruby 1.8.1.
The methods inside them can be called concurrently from multiple
threads.
Note that this is not the same as reentrant, where the same method can
be safely executing simultaneously in two threads.
Thread safety can be implemented easily by adding the appropriate
mutexes. Making a module reentrant requires more care.
Adam said:I'd like to call a particular inherited method rather than the one in my
immediate ancestor. For instance
class Parent
def to_s
super.to_s + " Parent-specific stuff here."
end
end
class Child < Parent
def to_s
# I want to call Object.to_s here ...
end
end
I can't figure out the right syntax. Any hints? For what it's worth I'm
using Ruby 1.8.1.
Normally I wouldn't want to skip an ancestor method for fear of
violating the Liskov Substitution Principle. For to_s, though, it seems
reasonable enough to me.
Pit said:Object.instance_method( :to_s ).bind( self ).call
tony summerfelt said:when i first read this i thought ok, that answers my question...but
after over thinking it, i'm not sure i see the difference.
i would think the same method running in two different threads is
either safely executing or it isn't.
i've gone to considerably length to make sure methods in my module are
thread safe as they access the same resource.
i've leaned on them
pretty heavily, with threaded code and the resource never gets
corrupted..
just wanted to make sure i was on the right track...
On Wed, 21 Jul 2004 01:20:56 +0900, you wrote:
=20
=20
when i first read this i thought ok, that answers my question...but
after over thinking it, i'm not sure i see the difference.
=20
i would think the same method running in two different threads is
either safely executing or it isn't.
=20
i've gone to considerably length to make sure methods in my module are
thread safe as they access the same resource. i've leaned on them
pretty heavily, with threaded code and the resource never gets
corrupted..
=20
just wanted to make sure i was on the right track...
Hunter said:Should this take a block, for completeness?
That's not a proof - at best it's an indication.![]()
Synchronizing with mutexes is another way to make method thread safe.
When you have a thread-safe method, it
can be called multiple times concurrently, but you may have only one
thread executing in the method, while the others are blocked waiting.
section only around a small part of the method. Only one thread can be
executing inside a critical section.)
do i assume that a mutex will handle that? in my testing it seems to
work ok (ie. i get what i expect)
...
Object.instance_method( :to_s ).bind( self ).call
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.