Skip to content

Conversation

da-viper
Copy link

On linux libdispatch set all the theads name as DispatchWorker because of the 16 byte limit of thread names.

https://github.com/swiftlang/swift-corelibs-libdispatch/blob/0bb6c10fa556722654917b4a18ba2dc39b18392a/src/queue.c#L6266-L6270

	#if HAVE_PTHREAD_SETNAME_NP 
	// pthread thread names are restricted to just 16 characters
	// including NUL. It does not make sense to pass the queue's
	// label as a name.
	pthread_setname_np(pthread_self(), "DispatchWorker");
	#endif

rust truncates the name that given

llvm::set_thread_name on linux currently uses the last 16 characters on linux as it tends to the more unique.

void llvm::set_thread_name(const Twine &Name) {
// Make sure the input is null terminated.
SmallString<64> Storage;
StringRef NameStr = Name.toNullTerminatedStringRef(Storage);
// Truncate from the beginning, not the end, if the specified name is too
// long. For one, this ensures that the resulting string is still null
// terminated, but additionally the end of a long thread name will usually
// be more unique than the beginning, since a common pattern is for similar
// threads to share a common prefix.
// Note that the name length includes the null terminator.
if (get_max_thread_name_length() > 0)
NameStr = NameStr.take_back(get_max_thread_name_length() - 1);
(void)NameStr;

zig returns an error if the name is too long.

On linux `libdispatch` set all the theads name as `DispatchWorker` because of the 16 byte limit of thread names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant