]> mj.ucw.cz Git - libucw.git/commitdiff
Adjust thread stack size according to radix sorter parameters.
authorMartin Mares <mj@ucw.cz>
Tue, 11 Sep 2007 16:59:29 +0000 (18:59 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 11 Sep 2007 16:59:29 +0000 (18:59 +0200)
lib/sorter/TODO
lib/sorter/array.c

index 32bd56fe3e4406c7d192626f5f714def674edd70..a3193083089ef4d7fc45c406cc3515161b4085d9 100644 (file)
@@ -3,7 +3,6 @@ o  Clean up introductory comments.
 o  Log messages should show both original and new size of the data. The speed
    should be probably calculated from the former.
 o  Buffer sizing in shep-export.
-o  Problems with thread stack limit in radix-sorting of arrays.
 
 Users of lib/sorter/array.h which might use radix-sorting:
 indexer/chewer.c
index 68ada9015968a8dc7c495a93c47cbe388c4595fb..4d64d7580c97d430e4684c7ef8e61844f67a7d81 100644 (file)
@@ -75,6 +75,15 @@ static uns asort_threads_use_count;
 static uns asort_threads_ready;
 static struct worker_pool asort_thread_pool;
 
+static uns
+rs_estimate_stack(void)
+{
+  // Stack space needed by the recursive radix-sorter
+  uns ctrsize = sizeof(uns) * (1 << CONFIG_UCW_RADIX_SORTER_BITS);
+  uns maxdepth = (64 / CONFIG_UCW_RADIX_SORTER_BITS) + 1;
+  return ctrsize * maxdepth;
+}
+
 void
 asort_start_threads(uns run)
 {
@@ -82,8 +91,11 @@ asort_start_threads(uns run)
   asort_threads_use_count++;
   if (run && !asort_threads_ready)
     {
-      ASORT_TRACE("Initializing thread pool (%d threads)", sorter_threads);
+      // XXX: If somebody overrides the radix-sorter parameters to insane values,
+      // he also should override the stack size to insane values.
+      asort_thread_pool.stack_size = default_thread_stack_size + rs_estimate_stack();
       asort_thread_pool.num_threads = sorter_threads;
+      ASORT_TRACE("Initializing thread pool (%d threads, %dK stack)", sorter_threads, asort_thread_pool.stack_size >> 10);
       worker_pool_init(&asort_thread_pool);
       asort_threads_ready = 1;
     }