Thread names--when do you need to know them?
Asked Answered
B

5

7

I created a SO question about naming conventions for threads a while ago. The question was something like, "How should you name a thread?"

Looking back, a thread name only matters if you have to read a thread's name.

Can you provide real-world examples of when you've had to examine threads and discern between them, relying on their names? This is platform/framework agnostic.

How (in what environment), did you do this?

Put another way, in what scenarios have you had to solve a problem and had to examine threads by name, and how did you accomplish this?

Biarritz answered 18/4, 2009 at 6:45 Comment(5)
generally thread names are really only useful for logging and debugging.Vestryman
Okay, so how, specifically, do you use a thread name for logging or debugging? What logging or debugging mechanisms tell you a thread's name, and how does that help you?Biarritz
This isn't platform agnostic. You can't name threads under Windows.Emission
Yes you can. Use SetThreadName: #479375Utopianism
Related question on how to set thread names in Linux: #778585Theodoretheodoric
H
3

When looking for connection leaks in java, it is sometimes useful to trace an object back to see which thread it was created by. In our case, it was the Finalizer thread. This led us to the conclusion that things were getting garbage collected, but not being Finalized fast enough. i.e. a bunch of stuff was waiting to be finalized, which was all done in one thread.

As a result, we learnt a lesson about not relying on Finalize.

Hydromedusa answered 18/4, 2009 at 7:5 Comment(1)
Yes, never rely on finalize or any kind of destructor to clean up critical resources!Vestryman
E
2

This question is currently tagged with 'linux' for no apparent reason... anyway, if you're using Visual Studio, the thread name appears in the threads window in the debugger, so if you're debugging an app with tons of threads, the name makes it super-easy to find 'the thread you care about' in this window in the debugger.

In short, I just use it because it interacts nicely with the debugger tooling.

Eldaelden answered 18/4, 2009 at 11:38 Comment(0)
J
1

Sometimes on Java EE application servers, it is useful to be able to trace all activity on a single thread, and these are usually given appropriate names by the pooling sub-system, eg. 'http-25', 'http-12' and so on.

Jaynajayne answered 18/4, 2009 at 8:51 Comment(0)
R
0

It's quite often really useful to do thread dumps of production servers to determine causes of hangs/slowdowns. In this case there's usually going to be a large amount of threads in different roles. In a java application you could be looking at quartz threads and possibly different thread pools that an application uses to establish performance guarantees. Arguably the thread pool name is usually more important than the actual thread name, but the individual thread names can also be significant if you're trying to identify a deadlocked thread. Since the threads usually have a name indicating its role, it helps to understand what's going on.

Ridgway answered 18/4, 2009 at 7:15 Comment(0)
A
0

I'm using thread names to help debug the realtime performance of a multithreaded robot control application written with the Orocos toolchain. Each component runs in a separate thread, and I will write shell scripts that use general purpose tools to manage the priorities of the threads and what cores they run on (and thus, indirectly, what threads preempt other threads, and when). The nice thing about doing it this way is that you can tune the performance of the program while it is running, which is especially helpful if you also rig up a continuously output performance metric.

Abrahamabrahams answered 30/10, 2013 at 8:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.