0

Because of a race during the shutdown of an application I work on, I want to control deletion of a thread that is in a third party library which does have a proper shutdown implemented. I know we need to fix this in the third party library, but for now I want to continue and solve the issue.

The thread is created using CreateThread. In the lpParameter a struct is supplied which contains the name of the thread. There are multiple threads created, so I want to iterate over the threads and find the thread by name in the struct.

Is it possible to list all threads for the current process and filter on the parameter with which the thread was created?

Matty
  • 134
  • 1
  • 7
  • Which library? Is its source code publicly available? – Daniel Langr Nov 20 '19 at 07:33
  • Threads don't have names. There is very little practical you can do about it if the library doesn't give you the option to ask the thread(s) to exit. So you just don't bother and force the program to exit(). It is such a common issue that they did something about it [in c++11](https://stackoverflow.com/a/9759272/17034). – Hans Passant Nov 20 '19 at 07:38
  • https://learn.microsoft.com/en-us/windows/win32/toolhelp/traversing-the-thread-list, don't imagine you can get hold of the thread parameters though – Alan Birtles Nov 20 '19 at 07:47
  • The lib is not open source – Matty Nov 20 '19 at 07:51
  • I know that the thread do not have names. The name is packed in the struct that is supplied as parameter during creation of the thread. Can I iterate the thread and then get the parameter with which it was created? – Matty Nov 20 '19 at 07:53
  • You can't. `lpParameter` is a caller-provided value. The semantics are at the discretion of the caller, so you cannot assume anything about this value. – IInspectable Nov 20 '19 at 12:50

0 Answers0