From: Caleb Clausen Date: 2009-06-01T02:00:38+09:00 Subject: Re: Runnin code at a certain time? On 5/30/09, Eric Hodel wrote: > On May 30, 2009, at 12:46, Caleb Clausen wrote: >> On 5/30/09, Eric Hodel wrote: >>>> Is there some particular danger that Thread#run will be called on my >>>> threads without my asking? >>> >>> If it's library code, yes. If it's application code, probably not. >> >> Can you be more specific? I'm curious as to how exactly this could >> happen. I suspect you speak from experience, but I can't see how if an >> application fiddles with a libraries internals in this way, that's not >> considered a bug in the application. > > Since threads are involved, it doesn't need to muck with any > internals, it just has to wake up the thread your sleep was running in: The only purpose of run is to break a call to sleep (or select, or join. Anything else?) If code external to my library decides to call run on me, it ought to know what it's doing. If something bad happens, it seems to me that that's a bug in the external code. > class YourLib > def your_sleep > sleep 1_000_000 > end > end > > class MyApp > # ... > def do_stuff > @threads << Thread.start do > # ... > YourLib.new.your_sleep > # ... > end > end > > def wakeup > @threads.each do |thread| > thread.run > end > end > end What application actually does this?