-
Notifications
You must be signed in to change notification settings - Fork 341
blocking on spawn not work as intended #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
for comparison, same logic but, with golang (because the blog said the runtime is inspired by Go) package main
// #include <unistd.h>
import "C"
import (
"fmt"
"runtime"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
num := runtime.GOMAXPROCS(-1)
for i := 1; i <= num; i++ {
wg.Add(1)
go blockingWork(wg.Done, i)
wg.Add(1)
go normalWork(wg.Done, i)
}
wg.Wait()
}
func blockingWork(done func(), i int) {
defer done()
for {
C.usleep((C.uint)((5 * time.Second).Microseconds())) // POSIX's usleep
fmt.Println("blocking_work", i)
}
}
func normalWork(done func(), i int) {
defer done()
for {
time.Sleep(1 * time.Second)
fmt.Println("normal_work", i)
}
} |
Hi @win-t, thanks for opening this issue. The new runtime wasn't merged due to some performance concerns. That might be why you're not seeing the numbers you were expecting. |
I see, I'm curious though, do you have the issue link for the performance concern discussion @yoshuawuyts 🙏 |
after read comments on #631 |
I don't read the code yet, but I guess because we need a mutex to steal work from other threads (to know which thread to steal), given that the number of thread is dynamic, and dealing with dynamic (shared mutable) requires a mutex |
in the blog it is said that:
so I tried to block all available thread (my machine has 4 core), but after a while, I don't see any new thread is spawned
shouldn't runtime spawn more OS thread for this?
The text was updated successfully, but these errors were encountered: