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

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

SGksIGlzIHRoZXJlIGFueSBkaWZmZXJlbmNlIGJldHdlZW4gZG9pbmc6CgogIHNsZWVwCgphbmQ6
CgogIFRocmVhZC5zdG9wCgo/CgpJbiBib3RoIGNhc2VzIHRoZSBjdXJyZW50IHRocmVhZCBpcyBp
biAic2xlZXAiIHN0YXRlLgoKQWxzbywgd2h5IHRoZXJlIGlzIG5vIHdheSB0byBzdG9wL3BhdXNl
L3NsZWVwIGEgdGhyZWFkIGRpZmZlcmVudCBvZiB0aGUgY3VycmVudD8KSSBtZWFuIHNvbWV0aGlu
ZyBhczoKCiAgdDEgPSBUaHJlYWQuY3VycmVudAogIFRocmVhZC5uZXcgeyB0MS5zbGVlcCB9ICA8
LS0tIFRoaXMgZG9lc24ndCBleGlzdCAobmVpdGhlciAjc3RvcCBvciAjcGF1c2UpCgoKVGhhbmtz
IGEgbG90LgoKCi0tIApJw7Fha2kgQmF6IENhc3RpbGxvCjxpYmNAYWxpYXgubmV0Pgo=
 
R

Robert Klemme

2008/9/10 I=F1aki Baz Castillo said:
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 c= urrent?
I mean something as:

t1 =3D Thread.current
Thread.new { t1.sleep } <--- This doesn't exist (neither #stop or #paus=
e)

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

Cheers

robert

--=20
use.inject do |as, often| as.you_can - without end
 
R

Robert Klemme

2008/9/10 I=F1aki Baz Castillo said:
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? ;-)

Cheers

robert

--=20
use.inject do |as, often| as.you_can - without end
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top