+template <>
+inline typename std::enable_if<
+ std::is_same<pthread_t, std::thread::native_handle_type>::value,
+ bool>::type
+setThreadName(std::thread::id id, StringPiece name) {
+ static_assert(
+ sizeof(std::thread::native_handle_type) == sizeof(decltype(id)),
+ "This assumes std::thread::id is a thin wrapper around "
+ "std::thread::native_handle_type, but that doesn't appear to be true.");
+ // In most implementations, std::thread::id is a thin wrapper around
+ // std::thread::native_handle_type, which means we can do unsafe things to
+ // extract it.
+ pthread_t ptid = *reinterpret_cast<pthread_t*>(&id);
+ return setThreadName(ptid, name);
+}
+