Stdlib module threading/threadpool.vitl

This page is a wiki-style reference for one concrete stdlib file. It explains what the file owns, where it fits in the family, and how to decide whether this is the right surface to depend on.

Visual portrait of threading/threadpool.vitl
Wiki-style portrait for threading/threadpool.vitl.

Family: threading

Kind: public stdlib surface

Page style: this reference follows the same “encyclopedic card + portrait + usage contract” logic as the keyword pages, but for stdlib modules.

Summary

Overview

FieldValue
Paththreading/threadpool.vitl
Familythreading
Kindpublic stdlib surface
Line count361
Declared procedures31
Declared forms/picks6

`threading/threadpool.vitl` is a public stdlib surface inside the `threading` family. It should be read as one focused slice of the broader family responsibility: Thread, mutex, and pool-based concurrency helpers.

Purpose

This file should be chosen because of responsibility, not because its name “sounds close enough”. Inside the threading family, it carries one focused part of the contract and keeps that responsibility separate from neighboring concerns.

  • Use this module when coordination and scheduling are explicit parts of the design.
  • A worker pool can process tasks in parallel while leaving task definition and result aggregation elsewhere.

Taxonomy

Think of this page as a generated encyclopedia entry rather than a hand-written tutorial. The goal is to show what kind of module this is, how dense it is, and what reading strategy makes sense before depending on it.

  • Large algorithm surface: this file exposes many procedures and likely acts as a domain toolkit rather than a single thin wrapper.
  • Owns domain vocabulary: the module declares data shapes in addition to executable helpers, so its types are part of the contract.
  • Has tuning constants: part of the module behavior is controlled by named constants that document default precision, limits, or policy.
  • Narrow dependency fan-in: a small set of imports suggests a focused collaboration surface.

Implementation profile

This profile is inferred directly from the source text. It does not replace reading the file, but it tells you quickly whether the module is mostly declarative, loop-heavy, branch-heavy, or organized around many small exits.

SignalCountWhat it suggests
if5Branching density and local decision-making.
while9Loop-heavy or iterative implementation style.
for5Collection-style traversal at source level.
match0Variant-driven branching or grammar-style decoding.
let23Local state and intermediate value density.
give34Number of explicit exit points and result shaping.

Top-level API inventory

SurfaceItems
Proceduresthreadpool_new, threadpool_submit, threadpool_submit_future, threadpool_pending_tasks, threadpool_wait_all, threadpool_wait_timeout, threadpool_active_tasks, threadpool_resize, threadpool_stats, threadpool_shutdown, threadpool_shutdown_immediate, forkjoin_create
FormsThreadPool, Task, ThreadPoolStats, ForkJoinTask, ScheduledTask, Thread
Picksnone declared at top level
ConstantsPOOL_ID_COUNTER, TASK_ID_COUNTER, FORKJOIN_ID_COUNTER, SCHEDULED_ID_COUNTER
Exportsnone declared at top level

Imported surfaces

  • vitte/stdlib/threading/thread use vitte/stdlib/threading/mutex use vitte/stdlib/collections/queue // ThreadPool

Position in family

This file is module 3 of 3 in the threading family when ordered by path. By procedure count it ranks 1, and by line count it ranks 1. Those ranks are useful as rough signals of breadth, not as quality judgments.

Declaration map

The declaration map turns raw source into a scan-friendly catalog. It is useful when the file is large enough that a reader wants to orient by kinds of surfaces first.

LineNameKindRole
1vitte/stdlib/threading/threadpoolspaceDeclares the namespace that anchors this file in the stdlib tree.
3vitte/stdlib/threading/threaduseImports a sibling or supporting surface used by the module.
4vitte/stdlib/threading/mutexuseImports a sibling or supporting surface used by the module.
5vitte/stdlib/collections/queueuseImports a sibling or supporting surface used by the module.
9ThreadPoolformIntroduces a structured data shape that other procedures can exchange.
20TaskformIntroduces a structured data shape that other procedures can exchange.
32threadpool_newprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
57threadpool_submitprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
69threadpool_submit_futureprocOwns coordination, scheduling, or concurrency behavior.
74threadpool_pending_tasksprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
79threadpool_wait_allprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
88threadpool_wait_timeoutprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
102threadpool_active_tasksprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
116threadpool_resizeprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
139ThreadPoolStatsformIntroduces a structured data shape that other procedures can exchange.
149threadpool_statsprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
169threadpool_shutdownprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
183threadpool_shutdown_immediateprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
196ForkJoinTaskformIntroduces a structured data shape that other procedures can exchange.
204forkjoin_createprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
216forkjoin_forkprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
228forkjoin_joinprocOwns path semantics, traversal, or normalization.
240ScheduledTaskformIntroduces a structured data shape that other procedures can exchange.
251scheduled_task_newprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
266scheduled_task_startprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
274scheduled_task_stopprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
279scheduled_task_cancelprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
285POOL_ID_COUNTERconstDefines a named constant reused across the module.
286TASK_ID_COUNTERconstDefines a named constant reused across the module.
287FORKJOIN_ID_COUNTERconstDefines a named constant reused across the module.
288SCHEDULED_ID_COUNTERconstDefines a named constant reused across the module.
290get_next_pool_idprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
295get_next_task_idprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
300get_next_forkjoin_idprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
305get_next_scheduled_idprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
310queue_newprocOwns a concrete data shape or the operations that maintain it.
314queue_pushprocOwns a concrete data shape or the operations that maintain it.
318queue_lenprocOwns a concrete data shape or the operations that maintain it.
322thread_is_aliveprocOwns coordination, scheduling, or concurrency behavior.
326thread_joinprocOwns path semantics, traversal, or normalization.
330thread_detachprocOwns coordination, scheduling, or concurrency behavior.
334thread_spawnprocOwns coordination, scheduling, or concurrency behavior.
342sleep_msprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
346timestamp_nowprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
350ThreadformIntroduces a structured data shape that other procedures can exchange.

The table is exhaustive for top-level declarations of the selected kinds. This file declares 45 matching surfaces.

Representative signatures

These signatures are shown in source order so the page keeps the feel of a reference manual, not just a keyword cloud.

  • form ThreadPool { (line 9)
  • form Task { (line 20)
  • proc threadpool_new(num_workers: int, name: string) -> ThreadPool { (line 32)
  • proc threadpool_submit(pool: ThreadPool, task: proc, priority: int) -> int { (line 57)
  • proc threadpool_submit_future<T>(pool: ThreadPool, task: proc, priority: int) -> int { (line 69)
  • proc threadpool_pending_tasks(pool: ThreadPool) -> int { (line 74)
  • proc threadpool_wait_all(pool: ThreadPool) -> bool { (line 79)
  • proc threadpool_wait_timeout(pool: ThreadPool, timeout_ms: int) -> bool { (line 88)
  • proc threadpool_active_tasks(pool: ThreadPool) -> int { (line 102)
  • proc threadpool_resize(pool: ThreadPool, new_size: int) -> bool { (line 116)
  • form ThreadPoolStats { (line 139)
  • proc threadpool_stats(pool: ThreadPool) -> ThreadPoolStats { (line 149)
  • proc threadpool_shutdown(pool: ThreadPool) -> bool { (line 169)
  • proc threadpool_shutdown_immediate(pool: ThreadPool) -> bool { (line 183)
  • form ForkJoinTask { (line 196)
  • proc forkjoin_create() -> ForkJoinTask { (line 204)
  • proc forkjoin_fork(pool: ThreadPool, task: ForkJoinTask, subtasks: [proc]) -> bool { (line 216)
  • proc forkjoin_join(pool: ThreadPool, task: ForkJoinTask) -> int { (line 228)

The list is intentionally capped here; the source file declares 41 matching signatures in total.

How to use this module

Start by reading the file as an ownership boundary. Ask three questions: what enters this module, what stable types or procedures it exports, and what adjacent module should stay outside of it.

  1. Read space and top-level imports first so the ownership boundary of threading/threadpool.vitl is explicit.
  2. Scan constants before procedures; they often encode precision, limits, or policy assumptions that explain later behavior.
  3. Read declared forms and picks before algorithms so the data vocabulary is stable in your head.
  4. Traverse procedures in source order; the early helpers usually explain the naming and numeric conventions used later.
  5. Only after that compare neighbor modules, because the right boundary choice matters more than memorizing one helper name.

User example

This example is generated from the actual stdlib module surface. Its job is not to be the smallest snippet possible; its job is to show a realistic consumer-shaped file that exercises the module and mirrors the language keywords the module itself relies on.

space demo/threading_threadpool
use vitte/stdlib/threading/threadpool
const SAMPLE_RETRIES: int = 1
const INITIAL_VALUE: int = 0
form CounterReport {
  ok: bool,
  value: int
}
proc run_example() -> CounterReport {
  let ready: bool = threadpool_new(1, "sample")
  let value: int = 0
  let released: bool = ready
  let wrote: bool = ready
  let ok: bool = ready
  if not ok {
    give CounterReport { ok: false, value: value }
  } else {
    give CounterReport { ok: true, value: value }
  }
}

Keyword coverage

This table makes the “all keywords of the module” requirement auditable. It compares the detected Vitte keywords in the source file with the generated consumer example above.

KeywordPresent in module sourceUsed in generated user example
spaceyesyes
useyesyes
constyesyes
formyesyes
procyesyes
letyesyes
setyesno
ifyesyes
elseyesyes
whileyesno
foryesno
giveyesyes
entryyesno
trueyesyes
falseyesyes
asyesno

Keywords still not exercised directly in the generated snippet: set, while, for, entry, as. The page still lists them here so the gap is visible.

Source shape

space vitte/stdlib/threading/threadpool
use vitte/stdlib/threading/thread
use vitte/stdlib/threading/mutex
use vitte/stdlib/collections/queue
// ThreadPool - Manages pool of reusable worker threads
form ThreadPool {
  id: int,
  num_workers: int,
  worker_threads: [Thread],
  task_queue: int,        // Queue ID

The excerpt is not meant to replace the file. It exists to make the module recognizable at first glance, the same way a Wikipedia infobox helps the reader orient before reading the whole article.

Source landmarks

Large files are easier to retain when they have visible landmarks. When the source contains explicit section banners, they are surfaced here; otherwise the first major declarations are used as anchors.

  • Line 1: space vitte/stdlib/threading/threadpool
  • Line 3: use vitte/stdlib/threading/thread
  • Line 4: use vitte/stdlib/threading/mutex
  • Line 5: use vitte/stdlib/collections/queue
  • Line 9: form ThreadPool {
  • Line 20: form Task {
  • Line 32: proc threadpool_new(num_workers: int, name: string) -> ThreadPool {
  • Line 57: proc threadpool_submit(pool: ThreadPool, task: proc, priority: int) -> int {

Source organization

When a file carries its own internal chaptering, those chapters usually reveal the intended reading order better than a flat symbol list. This section reconstructs that organization from the source itself.

File surfaces

Top-level items: 45. Procedures: 31. Data surfaces: 6. Constants: 4.

First visible names: vitte/stdlib/threading/threadpool, vitte/stdlib/threading/thread, vitte/stdlib/threading/mutex, vitte/stdlib/collections/queue, ThreadPool, Task, threadpool_new, threadpool_submit, threadpool_submit_future, threadpool_pending_tasks

Complete API catalog

This catalog is the exhaustive file-level index for the module. It is intentionally closer to a generated encyclopedia appendix than to a tutorial summary.

Constants

LineNameSignatureRole
285POOL_ID_COUNTERconst POOL_ID_COUNTER: int = 0Defines a named constant reused across the module.
286TASK_ID_COUNTERconst TASK_ID_COUNTER: int = 0Defines a named constant reused across the module.
287FORKJOIN_ID_COUNTERconst FORKJOIN_ID_COUNTER: int = 0Defines a named constant reused across the module.
288SCHEDULED_ID_COUNTERconst SCHEDULED_ID_COUNTER: int = 0Defines a named constant reused across the module.

Data surfaces

LineNameSignatureRole
9ThreadPoolform ThreadPool {Introduces a structured data shape that other procedures can exchange.
20Taskform Task {Introduces a structured data shape that other procedures can exchange.
139ThreadPoolStatsform ThreadPoolStats {Introduces a structured data shape that other procedures can exchange.
196ForkJoinTaskform ForkJoinTask {Introduces a structured data shape that other procedures can exchange.
240ScheduledTaskform ScheduledTask {Introduces a structured data shape that other procedures can exchange.
350Threadform Thread {Introduces a structured data shape that other procedures can exchange.

Procedures

LineNameSignatureRole
32threadpool_newproc threadpool_new(num_workers: int, name: string) -> ThreadPool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
57threadpool_submitproc threadpool_submit(pool: ThreadPool, task: proc, priority: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
69threadpool_submit_futureproc threadpool_submit_future<T>(pool: ThreadPool, task: proc, priority: int) -> int {Owns coordination, scheduling, or concurrency behavior.
74threadpool_pending_tasksproc threadpool_pending_tasks(pool: ThreadPool) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
79threadpool_wait_allproc threadpool_wait_all(pool: ThreadPool) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
88threadpool_wait_timeoutproc threadpool_wait_timeout(pool: ThreadPool, timeout_ms: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
102threadpool_active_tasksproc threadpool_active_tasks(pool: ThreadPool) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
116threadpool_resizeproc threadpool_resize(pool: ThreadPool, new_size: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
149threadpool_statsproc threadpool_stats(pool: ThreadPool) -> ThreadPoolStats {Represents one top-level surface in the file contract and should be read as part of the module boundary.
169threadpool_shutdownproc threadpool_shutdown(pool: ThreadPool) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
183threadpool_shutdown_immediateproc threadpool_shutdown_immediate(pool: ThreadPool) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
204forkjoin_createproc forkjoin_create() -> ForkJoinTask {Represents one top-level surface in the file contract and should be read as part of the module boundary.
216forkjoin_forkproc forkjoin_fork(pool: ThreadPool, task: ForkJoinTask, subtasks: [proc]) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
228forkjoin_joinproc forkjoin_join(pool: ThreadPool, task: ForkJoinTask) -> int {Owns path semantics, traversal, or normalization.
251scheduled_task_newproc scheduled_task_new(name: string, pool: ThreadPool, task_id: int, interval_ms: int) -> ScheduledTask {Represents one top-level surface in the file contract and should be read as part of the module boundary.
266scheduled_task_startproc scheduled_task_start(sched: ScheduledTask) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
274scheduled_task_stopproc scheduled_task_stop(sched: ScheduledTask) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
279scheduled_task_cancelproc scheduled_task_cancel(sched: ScheduledTask) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
290get_next_pool_idproc get_next_pool_id() -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
295get_next_task_idproc get_next_task_id() -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
300get_next_forkjoin_idproc get_next_forkjoin_id() -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
305get_next_scheduled_idproc get_next_scheduled_id() -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
310queue_newproc queue_new() -> int {Owns a concrete data shape or the operations that maintain it.
314queue_pushproc queue_push(q: int, value: int) -> bool {Owns a concrete data shape or the operations that maintain it.
318queue_lenproc queue_len(q: int) -> int {Owns a concrete data shape or the operations that maintain it.
322thread_is_aliveproc thread_is_alive(thread: Thread) -> bool {Owns coordination, scheduling, or concurrency behavior.
326thread_joinproc thread_join(thread: Thread) -> bool {Owns path semantics, traversal, or normalization.
330thread_detachproc thread_detach(thread: Thread) -> bool {Owns coordination, scheduling, or concurrency behavior.
334thread_spawnproc thread_spawn(name: string, entry: proc) -> Thread {Owns coordination, scheduling, or concurrency behavior.
342sleep_msproc sleep_ms(ms: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
346timestamp_nowproc timestamp_now() -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.

Imports

LineNameSignatureRole
3vitte/stdlib/threading/threaduse vitte/stdlib/threading/threadImports a sibling or supporting surface used by the module.
4vitte/stdlib/threading/mutexuse vitte/stdlib/threading/mutexImports a sibling or supporting surface used by the module.
5vitte/stdlib/collections/queueuse vitte/stdlib/collections/queueImports a sibling or supporting surface used by the module.

Integration boundaries

Within threading, this file should remain focused. If a future helper changes the host boundary, scheduling boundary, or data-shape boundary, it probably belongs in a neighbor module instead of being added here by convenience.

  • Family responsibility: Thread, mutex, and pool-based concurrency helpers.
  • Family architecture role: Use `threading` when the program needs explicit concurrency coordination rather than single-threaded transformation.

Composition guidance

Choose this module when

  • Choose threading/threadpool.vitl when the main question is owned by this module rather than by transport, storage, orchestration, or user-interface code.
  • Use this module when coordination and scheduling are explicit parts of the design.
  • A worker pool can process tasks in parallel while leaving task definition and result aggregation elsewhere.

Pause before extending it when

  • Avoid extending this file when the new helper mostly changes the boundary to host I/O, runtime coordination, or foreign integration instead of staying inside threading.
  • Check nearby modules such as threading/mutex.vitl, threading/thread.vitl before adding convenience wrappers here.

Relationship table

This table keeps the page closer to a real encyclopedia entry: a module is easier to understand when compared with its nearest alternatives in the same family.

NeighborProceduresData surfacesWhy compare it
threading/mutex.vitl304Shares the same family boundary but carries a distinct slice of responsibility.
threading/thread.vitl273Shares the same family boundary but carries a distinct slice of responsibility.

Neighbor modules