Difference between "sleep()" and "Thread.stop"?

Hi, is there any difference between doing:

sleep

and:

Thread.stop

?

In both cases the current thread is in “sleep” state.

Also, why there is no way to stop/pause/sleep a thread different of the
current?
I mean something as:

t1 = Thread.current
Thread.new { t1.sleep } <— This doesn’t exist (neither #stop or
#pause)

Thanks a lot.

2008/9/10 Iñaki Baz C. [email protected]:

Hi, is there any difference between doing:

sleep

and:

Thread.stop

#sleep resumes automatically after a given time, #stop does not.

In both cases the current thread is in “sleep” state.

Also, why there is no way to stop/pause/sleep a thread different of the current?
I mean something as:

t1 = Thread.current
Thread.new { t1.sleep } <— This doesn’t exist (neither #stop or #pause)

Why should it? With threads you use other mechanisms to control
execution, e.g. a blocking queue, synchronizing on a mutex etc.

Cheers

robert

2008/9/10, Robert K. [email protected]:

#sleep resumes automatically after a given time, #stop does not.

Object#sleep doesn’t resume if there is not parameter:
sleep # This sleeps forever

So, which difference exists between Object#sleep (with no parameter)
and Thread#stop ?

execution, e.g. a blocking queue, synchronizing on a mutex etc.
Well, it was just curiosity. Thanks for clarification.

Thanks.

2008/9/10 Iñaki Baz C. [email protected]:

#sleep resumes automatically after a given time, #stop does not.

Object#sleep doesn’t resume if there is not parameter:
sleep # This sleeps forever

I wasn’t aware of that. Learn something new every day. Thanks!

So, which difference exists between Object#sleep (with no parameter)
and Thread#stop ?

Well, #stop does not accept a time parameter, does it? :wink:

Cheers

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs