diff --git a/src/debug.cpp b/src/debug.cpp index 7705eea1a..fad134412 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -1671,8 +1671,13 @@ int memtest_test_linux_anonymous_maps(void) { } #endif /* HAVE_PROC_MAPS */ -static void killMainThread(void) { +static void killServerThreads(void) { int err; + for (int i = 0; i < cserver.cthreads; i++) { + if (g_pserver->rgthread[i] != pthread_self()) { + pthread_cancel(g_pserver->rgthread[i]); + } + } if (pthread_self() != cserver.main_thread_id && pthread_cancel(cserver.main_thread_id) == 0) { if ((err = pthread_join(cserver.main_thread_id,NULL)) != 0) { serverLog(LL_WARNING, "main thread can not be joined: %s", strerror(err)); @@ -1687,7 +1692,7 @@ static void killMainThread(void) { * Currently Redis does this only on crash (for instance on SIGSEGV) in order * to perform a fast memory check without other threads messing with memory. */ void killThreads(void) { - killMainThread(); + killServerThreads(); bioKillThreads(); } diff --git a/src/server.cpp b/src/server.cpp index 1ef7e3054..554c0ac43 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -5990,21 +5990,20 @@ int main(int argc, char **argv) { setOOMScoreAdj(-1); serverAssert(cserver.cthreads > 0 && cserver.cthreads <= MAX_EVENT_LOOPS); - pthread_t rgthread[MAX_EVENT_LOOPS]; pthread_attr_t tattr; pthread_attr_init(&tattr); pthread_attr_setstacksize(&tattr, 1 << 23); // 8 MB for (int iel = 0; iel < cserver.cthreads; ++iel) { - pthread_create(rgthread + iel, &tattr, workerThreadMain, (void*)((int64_t)iel)); + pthread_create(g_pserver->rgthread + iel, &tattr, workerThreadMain, (void*)((int64_t)iel)); if (cserver.fThreadAffinity) { #ifdef __linux__ cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(iel + cserver.threadAffinityOffset, &cpuset); - if (pthread_setaffinity_np(rgthread[iel], sizeof(cpu_set_t), &cpuset) == 0) + if (pthread_setaffinity_np(g_pserver->rgthread[iel], sizeof(cpu_set_t), &cpuset) == 0) { serverLog(LOG_INFO, "Binding thread %d to cpu %d", iel, iel + cserver.threadAffinityOffset + 1); } @@ -6024,7 +6023,7 @@ int main(int argc, char **argv) { this is so that all worker threads are orthogonal in their startup/shutdown */ void *pvRet; for (int iel = 0; iel < cserver.cthreads; ++iel) - pthread_join(rgthread[iel], &pvRet); + pthread_join(g_pserver->rgthread[iel], &pvRet); return 0; } diff --git a/src/server.h b/src/server.h index 0cf6498d2..c6b9a77b5 100644 --- a/src/server.h +++ b/src/server.h @@ -1488,6 +1488,7 @@ struct redisServer { ::dict *orig_commands; /* Command table before command renaming. */ struct redisServerThreadVars rgthreadvar[MAX_EVENT_LOOPS]; + pthread_t rgthread[MAX_EVENT_LOOPS]; std::atomic lruclock; /* Clock for LRU eviction */ std::atomic shutdown_asap; /* SHUTDOWN needed ASAP */