diff --git a/util/env_posix.cc b/util/env_posix.cc index 356008225..16c3d1c61 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -1396,6 +1396,15 @@ class PosixEnv : public Env { fprintf(stdout, "Created bg thread 0x%lx\n", (unsigned long)t); + + // Set the thread name to aid debugging +#if defined(_GNU_SOURCE) && defined(__GLIBC_PREREQ) && (__GLIBC_PREREQ(2, 12)) + char name_buf[16]; + snprintf(name_buf, sizeof name_buf, "rocksdb:bg%zu", bgthreads_.size()); + name_buf[sizeof name_buf - 1] = '\0'; + pthread_setname_np(t, name_buf); +#endif + bgthreads_.push_back(t); }