[Groonga-commit] groonga/groonga at 5bc6d6d [master] groonga: fix deadlock when thread_limit?max=1 is requested at once

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jul 6 13:40:23 JST 2017


Kouhei Sutou	2017-07-06 13:40:23 +0900 (Thu, 06 Jul 2017)

  New Revision: 5bc6d6d5682558f53c26a82968ee4aec1be06e45
  https://github.com/groonga/groonga/commit/5bc6d6d5682558f53c26a82968ee4aec1be06e45

  Message:
    groonga: fix deadlock when thread_limit?max=1 is requested at once
    
    The later thread_limit?max=1 doesn't wait the number of running threads
    is reduced. The first thread_limit?max=1 only waits the number of
    running threads is reduced.

  Modified files:
    src/groonga.c

  Modified: src/groonga.c (+11 -0)
===================================================================
--- src/groonga.c    2017-07-06 10:09:55 +0900 (0f72526)
+++ src/groonga.c    2017-07-06 13:40:23 +0900 (205201a)
@@ -513,12 +513,21 @@ groonga_set_thread_limit(uint32_t new_limit, void *data)
 {
   uint32_t i;
   uint32_t current_n_floating_threads;
+  static uint32_t n_changing_threads = 0;
+  uint32_t prev_n_changing_threads;
+
+  GRN_ATOMIC_ADD_EX(&n_changing_threads, 1, prev_n_changing_threads);
 
   MUTEX_LOCK_ENSURE(&grn_gctx, q_mutex);
   current_n_floating_threads = n_floating_threads;
   max_n_floating_threads = new_limit;
   MUTEX_UNLOCK(q_mutex);
 
+  if (prev_n_changing_threads > 0) {
+    GRN_ATOMIC_ADD_EX(&n_changing_threads, -1, prev_n_changing_threads);
+    return;
+  }
+
   if (current_n_floating_threads > new_limit) {
     for (i = 0; i < current_n_floating_threads; i++) {
       MUTEX_LOCK_ENSURE(&grn_gctx, q_mutex);
@@ -540,6 +549,8 @@ groonga_set_thread_limit(uint32_t new_limit, void *data)
     }
     grn_nanosleep(1000000);
   }
+
+  GRN_ATOMIC_ADD_EX(&n_changing_threads, -1, prev_n_changing_threads);
 }
 
 typedef struct {
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index