src/os/linux/vm/os_linux.cpp

Print this page
rev 3492 : imported patch linux_thread_name.patch

@@ -4342,13 +4342,20 @@
   int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
   assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
   return online_cpus;
 }
 
+#define MAXTHREADNAMESIZE 16
+
 void os::set_native_thread_name(const char *name) {
-  // Not yet implemented.
-  return;
+  if (name != NULL) {
+    // The maximum length is 16 (including the trailing \0), we copy
+    // the first 15 chars into the buffer.
+    char buf[MAXTHREADNAMESIZE];
+    snprintf(buf, sizeof(buf), "%s", name);
+    pthread_setname_np(pthread_self(), buf);
+  }
 }
 
 bool os::distribute_processes(uint length, uint* distribution) {
   // Not yet implemented.
   return false;