K
K
Kerby12342022-01-03 21:12:12
C++ / C#
Kerby1234, 2022-01-03 21:12:12

How to get thread id in C++ process?

How to get id and handles of all threads running only in C++ code? That is, only those threads that were created during the execution of the program.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2022-01-03
@Kerby1234

It is possible to get a list of all threads of one process via Thread32First/Thread32Next ( example ).
It is looked for in Google literally on "winapi list threads".

F
FoxOne, 2022-01-27
@FoxOne

If you create them, then the easiest way is to remember what you created there.
For example:
for std::thread there is std::thread::id get_id() const noexcept
for CreateThread - the last parameter is a pointer where to add id
for pthread_create - the first parameter is a pointer to pthread_t where id will be added on success

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question