concurrent

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncTask

type AsyncTask struct {
	ID uint64
	Fn func(res any) (any, error)
}

AsyncTask represents a task to be executed by the AsyncWorkerPool.

type AsyncTaskResult

type AsyncTaskResult struct {
	ID     uint64
	Result any
	Error  error
}

AsyncTaskResult holds the result of a AsyncTask execution.

type AsyncTaskResultStore

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

AsyncTaskResultStore manages the storage and retrieval of AsyncTaskResults.

func NewAsyncTaskResultStore

func NewAsyncTaskResultStore() *AsyncTaskResultStore

NewAsyncTaskResultStore creates a new AsyncTaskResultStore.

func (*AsyncTaskResultStore) GetNextJobID

func (s *AsyncTaskResultStore) GetNextJobID() uint64

GetNextJobID atomically increments and returns a new unique job ID.

func (*AsyncTaskResultStore) Stop

func (s *AsyncTaskResultStore) Stop()

Stop signals the AsyncTaskResultStore to stop processing new waits.

func (*AsyncTaskResultStore) Store

func (s *AsyncTaskResultStore) Store(result *AsyncTaskResult)

Store saves a AsyncTaskResult in the store and signals any waiting goroutines.

func (*AsyncTaskResultStore) Wait

func (s *AsyncTaskResultStore) Wait(jobID uint64) (*AsyncTaskResult, error)

Wait blocks until the result for the given jobID is available and returns it. The result is removed from the internal map after being retrieved.

type AsyncWorkerPool

type AsyncWorkerPool struct {
	*AsyncTaskResultStore // Embed the result store
	// contains filtered or unexported fields
}

AsyncWorkerPool runs tasks in a dedicated OS thread with a CUDA context.

func NewAsyncWorkerPool

func NewAsyncWorkerPool(nthread uint, createResource func() (any, error), cleanupResource func(any)) *AsyncWorkerPool

NewAsyncWorkerPool creates a new AsyncWorkerPool.

func (*AsyncWorkerPool) GetFirstError

func (w *AsyncWorkerPool) GetFirstError() error

GetFirstError returns the first internal error encountered by the worker.

func (*AsyncWorkerPool) Start

func (w *AsyncWorkerPool) Start(initFn func(res any) error, stopFn func(resource any) error)

Start begins the worker's execution loop.

func (*AsyncWorkerPool) Stop

func (w *AsyncWorkerPool) Stop()

Stop signals the worker to terminate and waits for it to finish.

func (*AsyncWorkerPool) Submit

func (w *AsyncWorkerPool) Submit(fn func(res any) (any, error)) (uint64, error)

Submit sends a task to the worker. Blocks if the task buffer is full (buffer size = nthread) until either:

  • the worker accepts the task — returns (jobID, nil), or
  • the pool is stopped via Stop / signal / internal error — returns (0, error).

Callers that cannot tolerate unbounded blocking on a saturated buffer must use SubmitContext with a context.Context deadline.

func (*AsyncWorkerPool) SubmitContext

func (w *AsyncWorkerPool) SubmitContext(ctx context.Context, fn func(res any) (any, error)) (uint64, error)

SubmitContext is Submit with a caller-supplied deadline / cancellation signal. Returns the context's error if it fires before the worker accepts the task. The pool-stopped path still wins over a still-live context — callers should treat that as "drop the task" the same way.

func (*AsyncWorkerPool) Wait

func (w *AsyncWorkerPool) Wait(jobID uint64) (*AsyncTaskResult, error)

Wait blocks until the result for the given jobID is available and returns it. The result is removed from the internal map after being retrieved.

type ThreadPoolExecutor

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

func NewThreadPoolExecutor

func NewThreadPoolExecutor(nthreads int) ThreadPoolExecutor

func (ThreadPoolExecutor) Execute

func (e ThreadPoolExecutor) Execute(
	ctx context.Context,
	nitems int,
	fn func(ctx context.Context, thread_id int, start, end int) error) (err error)

Jump to

Keyboard shortcuts

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