From: Paul Brannan Date: 2002-06-25T02:25:11+09:00 Subject: Re: detecting a socket dropping in multi-threaded app > Firestone, Mark - Technical Support (mark.firestone@gossgraphic.co.uk) wrote: > > How about this? My @who data structure is shared with a mutex between the > > threads. It keeps a list of the thread id with each person's username and > > whatever who is logged on. When someone hangs up, Ruby just kills the > > thread (I verified this with an experiment last night...) > > > > I write a thread that wakes up every so often and checks Thread.current, and > > compares that list with the list in @who, and if someone is missing from > > Thread.current, zaps them from the list. > > > > Is this a reasonable idea? Why not wrap your thread with an ensure block that removes the person from the list when it is executed? t = Thread.new do # add the person to the list begin loop do # Your logic here; when the socket (or other IO object) goes # away, break out of the loop. end ensure # remove the person from the list end end This reduces possibility for reading from a socket that isn't there, or for doing something for a user who isn't logged in. (I never received the original message, btw, so I'm not 100% sure I understand exactly what the problem is). Paul