From: Robert Klemme Date: 2005-08-29T22:37:33+09:00 Subject: Re: Associating a name with a thread? 2005/8/29, Andrew S. Townley : > > Hi. Me again. > > I'm doing some research/work using threads with ruby. I saw this in the > ri docs for Thread#inspect: > > --------------------------------------------------------- Thread#inspect > thr.inspect => string > ------------------------------------------------------------------------ > Dump the name, id, and status of _thr_ to a string. > > And was wondering how you assign a meaningful name to a thread. Right > now, I have about 2X as many threads created as I would've thought > (using Thread.list.length). Desk-checking the code doesn't show > anything obvious, but I have instrumented it to the point that I have > output with the Thread information, e.g. > > #: doing something > > But, what I want is to be able to do something like > > task1 = Thread.new("task1") { ... } > > or at least > > task1 = Thread.new { ... } > task1.name = "task1" > > to get it to show up during execution. > > Maybe I'm going about this the wrong way. Any pointers in the right > direction would be appreciated. I couldn't find exactly what you are looking for, but you can use thread local variables. So you can do t = Thread.new do ... end t[:name] = "my thread" HTH Kind regards robert