# Strange behaviour with sleep() in a thread

**URL:** <https://www.ruby-forum.com/t/strange-behaviour-with-sleep-in-a-thread/156313>\
**Category:** Ruby\
**Created:** [December 24, 2008, 11:00am UTC](https://www.ruby-forum.com/t/strange-behaviour-with-sleep-in-a-thread/156313 "2008-12-24T11:00:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [December 24, 2008, 11:00am UTC](https://www.ruby-forum.com/t/strange-behaviour-with-sleep-in-a-thread/156313/1 "2008-12-24T11:00:22Z")

</div>

I have a thread created with Thread.new that does some polling. I don’t  
want it to busy wait so I call the sleep method like so:

sleep(60)

```
...this should allow me to poll every minute which is good enough 

```

for my  
application. However, I’m finding that calling sleep from a thread in  
this  
manner often sleeps for a good deal longer than a minute. So far, I  
find it  
sleeping for about 8 or so minutes. The main thread is blocked in a  
gets  
call.  
What I’m actually trying to do is implement a simple timer. I’m  
trying  
to do something at a certain point in time, like a cron job, without  
busy  
waiting.  
Why is sleep behaving so strangely? Is there a simple way of doing  
what  
I’m trying to do?  
Thank you…

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [December 27, 2008, 1:04am UTC](https://www.ruby-forum.com/t/strange-behaviour-with-sleep-in-a-thread/156313/2 "2008-12-27T01:04:06Z")

</div>

> ```
> Why is sleep behaving so strangely? Is there a simple way of doing 
> 
> ```
> 
> what  
> If you’re on 1.8.x then your two threads are actually one “real thread”  
> running two green threads. One of the green threads [the gets] might be  
> blocking and not allowing control to return to the other.  
> Fix (should this be the case): make the one not block, or use 1.9  
> Cheers!  
> -=r
