From b67b8bfcc8a7b5bab81db3bf92e8a47f5faffdd6 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 27 Nov 2024 16:19:26 +0200 Subject: [PATCH] runtime: force runtime.nr_jobs() to return 1, while V is bootstrapping itself, from vc/ source, that was compiled with `-os cross` (fix #22991) --- vlib/runtime/runtime.v | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vlib/runtime/runtime.v b/vlib/runtime/runtime.v index 3ee524afd4..f087bfa1f8 100644 --- a/vlib/runtime/runtime.v +++ b/vlib/runtime/runtime.v @@ -11,6 +11,12 @@ import os // then `nr_jobs` will return that number instead. // This is useful for runtime tweaking of e.g. threaded or concurrent code. pub fn nr_jobs() int { + $if cross ? { + // A single thread is *more likely* to work consistently everywhere during bootstrapping. + // NB: the compiler itself uses runtime.nr_jobs() and sync.pool to process things in parallel + // in its cgen stage. Returning 1 here, increases the chances of it working on non linux systems. + return 1 + } mut cpus := nr_cpus() - 1 // allow for overrides, for example using `VJOBS=32 ./v test .` vjobs := os.getenv('VJOBS').int()