Skip to content

Commit

Permalink
Always truncate thread names on linux to 15 chars (16 with the null t…
Browse files Browse the repository at this point in the history
…erminator).

On Linux it is an error for a thread name to exceed 16 bytes. Thus also changing the VM thread pool to use the shorter "DartWorker" name.

Change-Id: I4c5cc2bfb831a5593a8652d6435631b9d3803720
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126163
Commit-Queue: Kirill Nikolaev <cyriln@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
  • Loading branch information
nichtverstehen authored and commit-bot@chromium.org committed Dec 4, 2019
1 parent 28fc037 commit eec49f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions runtime/vm/os_thread_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include "vm/os_thread.h"

#include <errno.h> // NOLINT
#include <errno.h> // NOLINT
#include <stdio.h>
#include <sys/time.h> // NOLINT

#include "platform/address_sanitizer.h"
Expand Down Expand Up @@ -119,8 +120,10 @@ static void* ThreadStart(void* data_ptr) {
uword parameter = data->parameter();
delete data;

// Set the thread name.
pthread_setname_np(pthread_self(), name);
// Set the thread name. There is 16 bytes limit on the name (including \0).
char truncated_name[16];
snprintf(truncated_name, ARRAY_SIZE(truncated_name), "%s", name);
pthread_setname_np(pthread_self(), truncated_name);

// Create new OSThread object and set as TLS for new thread.
OSThread* thread = OSThread::CreateOSThread();
Expand Down
9 changes: 6 additions & 3 deletions runtime/vm/os_thread_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include "vm/os_thread.h"

#include <errno.h> // NOLINT
#include <errno.h> // NOLINT
#include <stdio.h>
#include <sys/resource.h> // NOLINT
#include <sys/syscall.h> // NOLINT
#include <sys/time.h> // NOLINT
Expand Down Expand Up @@ -121,8 +122,10 @@ static void* ThreadStart(void* data_ptr) {
uword parameter = data->parameter();
delete data;

// Set the thread name.
pthread_setname_np(pthread_self(), name);
// Set the thread name. There is 16 bytes limit on the name (including \0).
char truncated_name[16];
snprintf(truncated_name, ARRAY_SIZE(truncated_name), "%s", name);
pthread_setname_np(pthread_self(), truncated_name);

// Create new OSThread object and set as TLS for new thread.
OSThread* thread = OSThread::CreateOSThread();
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void ThreadPool::Worker::StartThread() {
ASSERT(task_ != nullptr);
}
#endif
int result = OSThread::Start("Dart ThreadPool Worker", &Worker::Main,
int result = OSThread::Start("DartWorker", &Worker::Main,
reinterpret_cast<uword>(this));
if (result != 0) {
FATAL1("Could not start worker thread: result = %d.", result);
Expand Down

0 comments on commit eec49f3

Please sign in to comment.