coroutines: use photon work_pool when nr_jobs > 0, and use photon libc fn wrappers (#19711)

This commit is contained in:
Joe C 2023-11-01 04:12:52 +11:00 committed by GitHub
parent 57a7db11bf
commit a63f3e6f77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 122 additions and 12 deletions

View file

@ -0,0 +1,37 @@
// Build with (-gc none, until GC bug is fixed)
// v -gc none -use-coroutines coroutine_benchs.v
//
import coroutines
import time
import net.http
import sync
const run_time = 10 * time.second
fn request(mut mu sync.Mutex, count &int) {
for {
http.get('http://vlang.io/utc_now') or { panic(err) }
mu.@lock()
unsafe {
(*count)++
}
mu.unlock()
}
}
fn main() {
mut mu := sync.new_mutex()
mut count := 0
for _ in 0 .. 8 {
go request(mut mu, &count)
}
$if is_coroutine ? {
println('IS COROUTINE=true')
coroutines.sleep(run_time)
} $else {
println('IS COROUTINE=false')
time.sleep(run_time)
}
println('${count} requests made.')
}