Dear Developers: Here is a redundant usage of lock(which may potentially lead to performance, deadlock issue.) Thank you for your checking!
https://github.com/redis/redis/blob/6a5bac309e868deef749c36949723b415de2496f/src/networking.c#L3467
https://github.com/redis/redis/blob/6a5bac309e868deef749c36949723b415de2496f/src/networking.c#L3468
void *IOThreadMain(void *myid) {
...;
if (getIOPendingCount(id) == 0) {
pthread_mutex_lock(&io_threads_mutex[id]);
pthread_mutex_unlock(&io_threads_mutex[id]);
continue;
}
...;
}
Best,
Comment From: huangzhw
It's not redundant. As the comment said Give the main thread a chance to stop this thread.. If without these lines, main thread will not have chance to stop IO threads. If main thread holds lock, IO threads will block on lock.
Comment From: jenny-cheung
Thank you for your reply! I am curious about why the main thread needs to stop this IO thread? In addition, in my humble view, if the the main thread hasn't held the lock, the IO thread would continue to run without blocking. That is, the main thread only can stop the IO thread when it already holds the lock.
Comment From: huangzhw
When IO threads are enabled, they still may be not running. Redis will check whether it need IO threads and may stop IO threads. You can reference stopThreadedIOIfNeeded.
Yes, you can reference stopThreadedIO. It stops IO threads by acquiring locks.
Comment From: jenny-cheung
Thank you for your detailed answers!