@@ -178,8 +178,13 @@ extern fn __jule_trampolineRun()
178178// Calls schedthread with P.
179179extern let __jule_trampoline_schedthread: *unsafe
180180
181+ // The value of the COMAXPROCS.
182+ // Compiler will set it to zero for default value, which is initialized by runtime.
183+ // Otherwise, this is initialized by the compiler to a custom value before runtime initialized.
184+ let mut comaxprocs: i32 = 0
185+
181186// Returns the maximum number of CPUs that can be executing simultaneously.
182- fn COMAXPROCS(): int { ret numcpu }
187+ fn COMAXPROCS(): int { ret int(comaxprocs) }
183188
184189const (
185190 // The maximum count of the runnable coroutine queue of a P.
909914 //
910915 // Stealing is limited to a small fixed number of attempts to
911916 // avoid excessive contention and cache thrashing.
912- if m.spinning || 2*atomic::Load(&sched.nmspinning, atomic::Relaxed) < i32(COMAXPROCS()) -atomic::Load(&sched.npidle, atomic::Relaxed) {
917+ if m.spinning || 2*atomic::Load(&sched.nmspinning, atomic::Relaxed) < comaxprocs -atomic::Load(&sched.npidle, atomic::Relaxed) {
913918 if !m.spinning {
914919 becomeSpinning(m)
915920 }
@@ -1255,6 +1260,13 @@ async fn yield() {
12551260 park2(&m.c, tg, reasonNA).await
12561261}
12571262
1263+ fn asynctimeinit() {
1264+ // Initialize the comaxprocs variable.
1265+ if comaxprocs == 0 {
1266+ comaxprocs = i32(numcpu)
1267+ }
1268+ }
1269+
12581270#disable nilptr boundary
12591271fn schedinit() {
12601272 // Initialize the global scheduler instance.
@@ -1266,7 +1278,7 @@ fn schedinit() {
12661278 // Because we are in the program initialize state, no concurrency risk.
12671279
12681280 // Initialize Ps.
1269- maxprocs := i32(COMAXPROCS())
1281+ maxprocs := comaxprocs
12701282 sched.allp = make([]&p, maxprocs)
12711283 sched.npidle = maxprocs - sched.nm
12721284 mut i := i32(0)
@@ -1329,6 +1341,11 @@ fn sysmon() {
13291341 }
13301342}
13311343
1344+ fn sysmoninit() {
1345+ // Start the sysmon thread.
1346+ unsafe { threadSpawn((*unsafe)(uintptr(sysmon)), nil) }
1347+ }
1348+
13321349// Schedules some M to run the P (creates an M if necessary).
13331350// If P==nil, the behavior is undefined. P is always should be a valid pointer.
13341351// If spinning is set, the caller has incremented nmspinning and must provide a
0 commit comments