more robust defaults;
authorwenzelm
Thu, 15 Feb 2024 09:53:58 +0100
changeset 79613 7a432595fb66
parent 79612 8836386d6e3f
child 79614 58c0636e0ef5
more robust defaults;
src/Pure/Concurrent/multithreading.ML
src/Pure/Concurrent/multithreading.scala
--- a/src/Pure/Concurrent/multithreading.ML	Thu Feb 15 08:25:25 2024 +0100
+++ b/src/Pure/Concurrent/multithreading.ML	Thu Feb 15 09:53:58 2024 +0100
@@ -26,9 +26,10 @@
 (* physical processors *)
 
 fun num_processors () =
-  (case Thread.Thread.numPhysicalProcessors () of
-    SOME n => n
-  | NONE => Thread.Thread.numProcessors ());
+  Int.max
+    (case Thread.Thread.numPhysicalProcessors () of
+      SOME n => n
+    | NONE => Thread.Thread.numProcessors (), 1);
 
 
 (* max_threads *)
@@ -38,7 +39,7 @@
 fun max_threads_result m =
   if Thread_Data.is_virtual then 1
   else if m > 0 then m
-  else Int.min (Int.max (num_processors (), 1), 8);
+  else Int.min (num_processors (), 8);
 
 val max_threads_state = ref 1;
 
--- a/src/Pure/Concurrent/multithreading.scala	Thu Feb 15 08:25:25 2024 +0100
+++ b/src/Pure/Concurrent/multithreading.scala	Thu Feb 15 09:53:58 2024 +0100
@@ -15,7 +15,7 @@
     if (ssh.isabelle_platform.is_macos) {
       val result = ssh.execute("sysctl -n hw.physicalcpu").check
       Library.trim_line(result.out) match {
-        case Value.Int(n) => n
+        case Value.Int(n) => n max 1
         case _ => 1
       }
     }
@@ -36,7 +36,7 @@
           case _ =>
         }
       }
-      physical_cores.valuesIterator.sum.max(1)
+      physical_cores.valuesIterator.sum max 1
     }
 
 
@@ -44,6 +44,6 @@
 
   def max_threads(): Int = {
     val m = Value.Int.unapply(System.getProperty("isabelle.threads", "0")) getOrElse 0
-    if (m > 0) m else (num_processors() max 1) min 8
+    if (m > 0) m else num_processors() min 8
   }
 }