Commit 43c0c2c5 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Don't invoke undefined behavior when getting the pthread_t out of std::thread::id

Summary: This assumes I understand strict-aliasing rules correctly.

Reviewed By: yfeldblum

Differential Revision: D4900118

fbshipit-source-id: edba535d3ba799ac665d3f859dc4154b2c1b22cb
parent 532b8c01
...@@ -85,7 +85,8 @@ inline bool setThreadName(std::thread::id id, StringPiece name) { ...@@ -85,7 +85,8 @@ inline bool setThreadName(std::thread::id id, StringPiece name) {
// In most implementations, std::thread::id is a thin wrapper around // In most implementations, std::thread::id is a thin wrapper around
// std::thread::native_handle_type, which means we can do unsafe things to // std::thread::native_handle_type, which means we can do unsafe things to
// extract it. // extract it.
pthread_t ptid = *reinterpret_cast<pthread_t*>(&id); pthread_t ptid;
std::memcpy(&ptid, &id, sizeof(pthread_t));
return setThreadName(ptid, name); return setThreadName(ptid, name);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment