goroutinesis experimental. It landed after0.5.1, soimport goroutinesis not available in that release.
Go-style goroutine runtime for V, implementing the GMP
(Goroutine-Machine-Processor) scheduling model translated
from the Go runtime (src/runtime/proc.go, runtime2.go,
chan.go).
This module provides lightweight goroutines for V's go
keyword, as opposed to spawn which creates OS threads.
// `go` launches a goroutine (lightweight, scheduled by GMP)
go expensive_computation()
// `spawn` launches an OS thread (traditional V behavior)
spawn blocking_io_task()
Translated from Go's runtime source:
| Go Source | V Module File | Purpose |
|---|---|---|
runtime2.go |
goroutines.v |
Core data structures (G, M, P, Sched) |
proc.go |
scheduler.v |
Scheduler loop, work stealing, run queues |
proc.go |
park.v |
gopark/goready, Sudog, WaitQ |
proc.go |
init.v |
Initialization (schedinit, procresize) |
chan.go |
chan.v |
Channel implementation |
| asm (gogo/gosave) | context_nix.c.v |
Context switching (ucontext) |
| asm (gogo/gosave) | context_windows.c.v |
Context switching (Windows fibers) |