0 branches
Tree Top files
Code
Clone with HTTPS:
56 years ago
..
examples all: super_batch3 fixes last Apr 13 10.02 KB
chan.v all: vfmt 4 files last Mar 17 6.43 KB
tls.c goroutines: fix test last Mar 18 3.93 KB

goroutines

goroutines is experimental. It landed after 0.5.1, so import goroutines is 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).

Overview

This module provides lightweight goroutines for V's go keyword, as opposed to spawn which creates OS threads.

GMP Model

Key Features

Usage

// `go` launches a goroutine (lightweight, scheduled by GMP)
go expensive_computation()

// `spawn` launches an OS thread (traditional V behavior)
spawn blocking_io_task()

Architecture

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)

References