Limit pthread thread name to 16 bytes.

This is a documented pthread restriction. Passing longer strings has no
effect (i.e. thread name is not set).
This commit is contained in:
Bartosz Taudul 2017-09-22 21:45:35 +02:00
parent 21fd14397d
commit bd622c304a

View File

@ -48,7 +48,18 @@ void SetThreadName( std::thread& thread, const char* name )
}
# endif
#else
pthread_setname_np( thread.native_handle(), name );
const auto sz = strlen( name );
if( sz <= 15 )
{
pthread_setname_np( thread.native_handle(), name );
}
else
{
char buf[16];
memcpy( buf, name, 15 );
buf[15] = '\0';
pthread_setname_np( thread.native_handle(), sz );
}
#endif
}