If a thread has a name, top -H will display it in parentheses after the executable name. One option would be to print the tid there if the thread has no name.