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

Discussion in 'Ruby' started by Iñaki Baz Castillo, Sep 10, 2008.

  1. SGksIGlzIHRoZXJlIGFueSBkaWZmZXJlbmNlIGJldHdlZW4gZG9pbmc6CgogIHNsZWVwCgphbmQ6
    CgogIFRocmVhZC5zdG9wCgo/CgpJbiBib3RoIGNhc2VzIHRoZSBjdXJyZW50IHRocmVhZCBpcyBp
    biAic2xlZXAiIHN0YXRlLgoKQWxzbywgd2h5IHRoZXJlIGlzIG5vIHdheSB0byBzdG9wL3BhdXNl
    L3NsZWVwIGEgdGhyZWFkIGRpZmZlcmVudCBvZiB0aGUgY3VycmVudD8KSSBtZWFuIHNvbWV0aGlu
    ZyBhczoKCiAgdDEgPSBUaHJlYWQuY3VycmVudAogIFRocmVhZC5uZXcgeyB0MS5zbGVlcCB9ICA8
    LS0tIFRoaXMgZG9lc24ndCBleGlzdCAobmVpdGhlciAjc3RvcCBvciAjcGF1c2UpCgoKVGhhbmtz
    IGEgbG90LgoKCi0tIApJw7Fha2kgQmF6IENhc3RpbGxvCjxpYmNAYWxpYXgubmV0Pgo=
     
    Iñaki Baz Castillo, Sep 10, 2008
    #1
    1. Advertising

  2. 2008/9/10 I=F1aki Baz Castillo <>:
    > 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, Sep 10, 2008
    #2
    1. Advertising

  3. 2008/9/10 I=F1aki Baz Castillo <>:
    > 2008/9/10, Robert Klemme <>:
    >> 2008/9/10 I=F1aki Baz Castillo <>:
    >>
    >> > 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
     
    Robert Klemme, Sep 10, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,236
  2. Gonzalo Moreno
    Replies:
    2
    Views:
    12,440
  3. Benji
    Replies:
    34
    Views:
    1,178
    pkriens
    Oct 28, 2005
  4. Sam Roberts
    Replies:
    16
    Views:
    381
    Daniel Berger
    Feb 18, 2005
  5. Richard
    Replies:
    7
    Views:
    236
    Richard
    May 22, 2007
Loading...

Share This Page