-
-
Save minh0722/51fc70e59142a38d75f50bb904d26b45 to your computer and use it in GitHub Desktop.
C++ human-readable thread id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <thread> | |
#include <atomic> | |
std::size_t get_thread_id() noexcept { | |
static std::atomic<std::size_t> thread_idx{0}; | |
thread_local std::size_t id = thread_idx; | |
thread_idx++; | |
return id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment