parallel

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 3 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package parallel shares a job of many tasks among the goroutines of a pool kept for the whole game: the caller's own and the pool's, each known by its number.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Part

func Part(n, k, i int) (from, to int)

Part is the items [from, to) of the i-th of k tasks sharing n items in order.

Types

type Batch

type Batch struct {
	// contains filtered or unexported fields
}

Batch is the tasks of one Begin; Add and Wait are its caller's.

func (*Batch) Add

func (b *Batch) Add(n int)

Add makes n more tasks, numbered on from the last; the pool's workers take them at once.

func (*Batch) Wait

func (b *Batch) Wait()

Wait closes the batch to tasks and works on it as worker 0 till every task is done.

type Forkable

type Forkable[R any] interface {
	Fork() R
}

Forkable reads state on one goroutine at a time: Fork is one more, for another.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool is Size goroutines sharing the tasks of one Batch at a time: worker 0, the caller of Wait, and Size−1 of the pool's own, waiting between batches. Size and Parts take a nil Pool for one goroutine.

func New

func New(size int) *Pool

New is a pool of size goroutines, the caller's among them; 0 or less as many as there are CPUs.

func (*Pool) Begin

func (p *Pool) Begin(task func(w, i int), idle func(w int)) *Batch

Begin starts a batch: task(w, i) runs on worker w for every task i added; idle(w), if not nil, once on each worker the first time it finds no task left. Functions made once allocate nothing.

func (*Pool) Parts

func (p *Pool) Parts(n, least, limit int) int

Parts is how many tasks n items make, each of at least least of them: no more than limit — 0 for the pool's Size — nor the Size, and never fewer than 1.

func (*Pool) Size

func (p *Pool) Size() int

Size is how many goroutines share a batch, the caller's among them.

type Reads

type Reads[R Forkable[R]] []R

Reads are a Forkable's reads for the workers of a pool, by worker: the first given, a Fork of it each other.

func NewReads

func NewReads[R Forkable[R]](first R, p *Pool) Reads[R]

NewReads is first, worker 0's, and a Fork of it for every other worker of p.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL