[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Iñaki Baz Castillo

9/10/2008 1:48:00 PM

SGksIGlzIHRoZXJlIGFueSBkaWZmZXJlbmNlIGJldHdlZW4gZG9pbmc6CgogIHNsZWVwCgphbmQ6
CgogIFRocmVhZC5zdG9wCgo/CgpJbiBib3RoIGNhc2VzIHRoZSBjdXJyZW50IHRocmVhZCBpcyBp
biAic2xlZXAiIHN0YXRlLgoKQWxzbywgd2h5IHRoZXJlIGlzIG5vIHdheSB0byBzdG9wL3BhdXNl
L3NsZWVwIGEgdGhyZWFkIGRpZmZlcmVudCBvZiB0aGUgY3VycmVudD8KSSBtZWFuIHNvbWV0aGlu
ZyBhczoKCiAgdDEgPSBUaHJlYWQuY3VycmVudAogIFRocmVhZC5uZXcgeyB0MS5zbGVlcCB9ICA8
LS0tIFRoaXMgZG9lc24ndCBleGlzdCAobmVpdGhlciAjc3RvcCBvciAjcGF1c2UpCgoKVGhhbmtz
IGEgbG90LgoKCi0tIApJw7Fha2kgQmF6IENhc3RpbGxvCjxpYmNAYWxpYXgubmV0Pgo=

2 Answers

Robert Klemme

9/10/2008 1:54:00 PM

0

2008/9/10 I=F1aki Baz Castillo <ibc@aliax.net>:
> 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

Robert Klemme

9/10/2008 2:33:00 PM

0

2008/9/10 I=F1aki Baz Castillo <ibc@aliax.net>:
> 2008/9/10, Robert Klemme <shortcutter@googlemail.com>:
>> 2008/9/10 I=F1aki Baz Castillo <ibc@aliax.net>:
>>
>> > Hi, is there any difference between doing:
>> >
>> > sleep
>> >
>> > and:
>> >
>> > Thread.stop
>>
>> #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? ;-)

Cheers

robert

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