On 31 May 2009, at 13:00, Caleb Clausen wrote:
> On 5/30/09, Eric Hodel <drbrain / segment7.net> wrote:
>> On May 30, 2009, at 12:46, Caleb Clausen wrote:
>>> On 5/30/09, Eric Hodel <drbrain / segment7.net> 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.

In general if you're writing a library that makes use of threads it's  
your responsibility to make them behave correctly when 'interrupted'  
by application code. Otherwise you have a fragile library that will  
greatly complicate debugging for its users.


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason