Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
get_number_of_threads, windows
#include <windows.h> #include <tlhelp32.h> #include <memory> #include <iostream> unsigned get_number_of_threads(DWORD process) { std::shared_ptr<void> snapshot(::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0), [](HANDLE handle) { ::CloseHandle(handle); }); if (snapshot.get() == INVALID_HANDLE_VALUE) { throw std::exception("CreateToolhelp32Snapshot failed"); } ::THREADENTRY32 thread_entry { sizeof(thread_entry) }; if (!::Thread32First(snapshot.get(), &thread_entry)) { throw std::exception("Thread32First failed"); } unsigned result = 0; do { if (thread_entry.th32OwnerProcessID == process) { result++; } } while (::Thread32Next(snapshot.get(), &thread_entry)); return result; } int main(void) { std::cout << get_number_of_threads(::GetCurrentProcessId()) << std::endl; }
run
|
edit
|
history
|
help
0
Wide string conversion with multibyte chars and locale + concatenation
Dices by GOOSE
ADL of operator expression & unqualified function call
Data structure alignment
Templatized Visitor Pattern Example
Eight Queen
xxx
#21.2
ExtThes_Uniquify
Visual C++ template instantiation