http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57060
Bug #: 57060 Summary: std::this_thread::get_id() == std::thread::id::id() without -pthread Classification: Unclassified Product: gcc Version: 4.7.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: r...@gcc.gnu.org #include <thread> #include <cassert> int main() { std::thread::id me = std::this_thread::get_id(); std::thread::id nobody; assert( me != nobody ); } This program should always succeed, but on GNU/Linux when not linking to libpthread.so the return value of pthread_self() is pthread_t(0) i.e. the same as the value set by the default-constructor of std::thread::id One solution would be to use a different value for the default-constructed value, possibly -1 if that cannot be a value pthread_t value. We still have the issue I described at http://gcc.gnu.org/ml/libstdc++/2011-03/msg00068.html regarding using pthread_equal() on invalid thread IDs, which could be handled by making operator== check for the invalid value and avoid a call to pthread_equal.