Skip to content

Instantly share code, notes, and snippets.

@minh0722
Forked from drodil/thread_id2.cpp
Created January 17, 2019 16:19
Show Gist options
  • Save minh0722/51fc70e59142a38d75f50bb904d26b45 to your computer and use it in GitHub Desktop.
Save minh0722/51fc70e59142a38d75f50bb904d26b45 to your computer and use it in GitHub Desktop.
C++ human-readable thread id
#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