From f5a8a97a43081d0cb6f4affd7ba5e812a8f6801f Mon Sep 17 00:00:00 2001 From: John Sully Date: Thu, 3 Jun 2021 04:43:38 +0000 Subject: [PATCH] Fix collab issue #26 Former-commit-id: 2392879772a77fc30c856488b9911d194ced827b --- src/rdb.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/rdb.cpp b/src/rdb.cpp index a1a3d7301..500291794 100644 --- a/src/rdb.cpp +++ b/src/rdb.cpp @@ -2797,6 +2797,19 @@ public: vars.clients_pending_asyncwrite = listCreate(); serverTL = &vars; aeSetThreadOwnsLockOverride(true); + + // We will inheret the server thread's affinity mask, clear it as we want to run on a different core. + cpu_set_t *cpuset = CPU_ALLOC(std::thread::hardware_concurrency()); + if (cpuset != nullptr) { + size_t size = CPU_ALLOC_SIZE(std::thread::hardware_concurrency()); + CPU_ZERO_S(size, cpuset); + for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) { + CPU_SET_S(i, size, cpuset); + } + pthread_setaffinity_np(pthread_self(), size, cpuset); + CPU_FREE(cpuset); + } + for (;;) { std::unique_lock lock(queue.mutex); if (listLength(queue.listJobs) == 0 && queue.queuefn.empty()) {