threadpool

package
v2.0.0-...-eb6a9d5 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package threadpool offers a pool of workers implemented using goroutines.

Create a new thread pool by calling NewThreadPool and specify the number of workers wanted and a work queue size. If the work queue is full when a new task is pushed, the thread pool will block until another task finishes.

Tasks can be any objects that implement the Runnable interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runnable

type Runnable interface {
	Run()
}

Runnable defines an interface with a Run function to be executed by a thread in a thread pool.

type ThreadPool

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

ThreadPool is a thread pool object used to execute tasks in parallel.

func NewThreadPool

func NewThreadPool(threads int, queueSize int) *ThreadPool

NewThreadPool creates a new ThreadPool object and starts the worker threads.

func (*ThreadPool) Close

func (p *ThreadPool) Close()

Close closes the threadpool and frees up the threads.

func (*ThreadPool) CurrentCount

func (p *ThreadPool) CurrentCount() int

CurrentCount returns the current number of tasks processed.

func (*ThreadPool) Done

func (p *ThreadPool) Done() bool

Done returns true if there are no tasks in flight.

func (*ThreadPool) Execute

func (p *ThreadPool) Execute(task Runnable)

Execute adds a task to the task queue to be picked by a worker thread. It will block if the queue is full.

func (*ThreadPool) Wait

func (p *ThreadPool) Wait()

Wait waits for all the tasks in flight to be processed.

Jump to

Keyboard shortcuts

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