runtime: force runtime.nr_jobs() to return 1, while V is bootstrapping itself, from vc/ source, that was compiled with -os cross (fix #22991)

This commit is contained in:
Delyan Angelov 2024-11-27 16:19:26 +02:00
parent aeaf607259
commit b67b8bfcc8
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -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()