Stdlib module threading/thread.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/thread.vitl
Wiki-style portrait for threading/thread.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/thread.vitl
Familythreading
Kindpublic stdlib surface
Line count248
Declared procedures27
Declared forms/picks3

`threading/thread.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.
  • Minimal top-level dependencies: the module reads as mostly self-contained from its opening declarations.

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
if7Branching density and local decision-making.
while2Loop-heavy or iterative implementation style.
for2Collection-style traversal at source level.
match0Variant-driven branching or grammar-style decoding.
let7Local state and intermediate value density.
give33Number of explicit exit points and result shaping.

Top-level API inventory

SurfaceItems
Proceduresthread_new, thread_start, thread_spawn, thread_current_id, thread_name, thread_set_name, thread_join, thread_join_timeout, thread_detach, thread_is_alive, thread_get_state, thread_get_result
FormsThread, ThreadLocal, ThreadStats
Picksnone declared at top level
ConstantsTHREAD_ID_COUNTER, THREADLOCAL_ID_COUNTER
Exportsnone declared at top level

Imported surfaces

This file does not advertise a top-level `use` surface in its opening declarations. That often means it is either self-contained or an aggregation layer.

Position in family

This file is module 2 of 3 in the threading family when ordered by path. By procedure count it ranks 3, and by line count it ranks 3. 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/threadspaceDeclares the namespace that anchors this file in the stdlib tree.
5ThreadformIntroduces a structured data shape that other procedures can exchange.
18ThreadLocalformIntroduces a structured data shape that other procedures can exchange.
24thread_newprocOwns coordination, scheduling, or concurrency behavior.
42thread_startprocOwns coordination, scheduling, or concurrency behavior.
61thread_spawnprocOwns coordination, scheduling, or concurrency behavior.
68thread_current_idprocOwns coordination, scheduling, or concurrency behavior.
73thread_nameprocOwns coordination, scheduling, or concurrency behavior.
78thread_set_nameprocOwns coordination, scheduling, or concurrency behavior.
84thread_joinprocOwns path semantics, traversal, or normalization.
97thread_join_timeoutprocOwns path semantics, traversal, or normalization.
112thread_detachprocOwns coordination, scheduling, or concurrency behavior.
123thread_is_aliveprocOwns coordination, scheduling, or concurrency behavior.
128thread_get_stateprocOwns coordination, scheduling, or concurrency behavior.
133thread_get_resultprocOwns coordination, scheduling, or concurrency behavior.
142thread_get_errorprocOwns coordination, scheduling, or concurrency behavior.
147thread_set_stack_sizeprocOwns coordination, scheduling, or concurrency behavior.
157thread_set_daemonprocOwns coordination, scheduling, or concurrency behavior.
163thread_set_priorityprocOwns coordination, scheduling, or concurrency behavior.
169cpu_countprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
174thread_yieldprocOwns coordination, scheduling, or concurrency behavior.
179thread_get_allprocOwns coordination, scheduling, or concurrency behavior.
185ThreadStatsformIntroduces a structured data shape that other procedures can exchange.
193thread_statsprocOwns coordination, scheduling, or concurrency behavior.
206threadlocal_newprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
215threadlocal_setprocOwns a concrete data shape or the operations that maintain it.
220threadlocal_getprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
229THREAD_ID_COUNTERconstDefines a named constant reused across the module.
230THREADLOCAL_ID_COUNTERconstDefines a named constant reused across the module.
232get_next_thread_idprocOwns coordination, scheduling, or concurrency behavior.
237get_next_threadlocal_idprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
242sleep_msprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
246timestamp_nowprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.

The table is exhaustive for top-level declarations of the selected kinds. This file declares 33 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 Thread { (line 5)
  • form ThreadLocal<T> { (line 18)
  • proc thread_new(name: string) -> Thread { (line 24)
  • proc thread_start(thread: Thread, entry: proc) -> bool { (line 42)
  • proc thread_spawn(name: string, entry: proc) -> Thread { (line 61)
  • proc thread_current_id() -> int { (line 68)
  • proc thread_name(thread: Thread) -> string { (line 73)
  • proc thread_set_name(thread: Thread, name: string) -> bool { (line 78)
  • proc thread_join(thread: Thread) -> bool { (line 84)
  • proc thread_join_timeout(thread: Thread, timeout_ms: int) -> bool { (line 97)
  • proc thread_detach(thread: Thread) -> bool { (line 112)
  • proc thread_is_alive(thread: Thread) -> bool { (line 123)
  • proc thread_get_state(thread: Thread) -> int { (line 128)
  • proc thread_get_result(thread: Thread) -> int { (line 133)
  • proc thread_get_error(thread: Thread) -> string { (line 142)
  • proc thread_set_stack_size(thread: Thread, size: int) -> bool { (line 147)
  • proc thread_set_daemon(thread: Thread, is_daemon: bool) -> bool { (line 157)
  • proc thread_set_priority(thread: Thread, priority: int) -> bool { (line 163)

The list is intentionally capped here; the source file declares 32 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/thread.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_thread
const SAMPLE_RETRIES: int = 1
const INITIAL_VALUE: int = 0
form CounterReport {
  ok: bool,
  value: int
}
proc run_example() -> CounterReport {
  let ready: bool = thread_new("sample")
  let value: int = 0
  let released: bool = ready
  let wrote: bool = ready
  let ok: bool = ready and wrote and released
  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
constyesyes
formyesyes
procyesyes
letyesyes
setyesno
ifyesyes
whileyesno
foryesno
giveyesyes
entryyesno
trueyesyes
falseyesyes
andyesyes
notyesyes

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

Source shape

space vitte/stdlib/threading/thread
// Thread management and lifecycle
form Thread {
  id: int,
  name: string,
  state: int,            // 0=new, 1=running, 2=finished, 3=detached, 4=error
  handle: int,           // OS thread handle
  result: int,           // Exit code
  error: string,         // Error message
  stack_size: int,       // Custom stack size (0=default)

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/thread
  • Line 5: form Thread {
  • Line 18: form ThreadLocal<T> {
  • Line 24: proc thread_new(name: string) -> Thread {
  • Line 42: proc thread_start(thread: Thread, entry: proc) -> bool {
  • Line 61: proc thread_spawn(name: string, entry: proc) -> Thread {
  • Line 68: proc thread_current_id() -> int {
  • Line 73: proc thread_name(thread: Thread) -> string {

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: 33. Procedures: 27. Data surfaces: 3. Constants: 2.

First visible names: vitte/stdlib/threading/thread, Thread, ThreadLocal, thread_new, thread_start, thread_spawn, thread_current_id, thread_name, thread_set_name, thread_join

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
229THREAD_ID_COUNTERconst THREAD_ID_COUNTER: int = 0Defines a named constant reused across the module.
230THREADLOCAL_ID_COUNTERconst THREADLOCAL_ID_COUNTER: int = 0Defines a named constant reused across the module.

Data surfaces

LineNameSignatureRole
5Threadform Thread {Introduces a structured data shape that other procedures can exchange.
18ThreadLocalform ThreadLocal<T> {Introduces a structured data shape that other procedures can exchange.
185ThreadStatsform ThreadStats {Introduces a structured data shape that other procedures can exchange.

Procedures

LineNameSignatureRole
24thread_newproc thread_new(name: string) -> Thread {Owns coordination, scheduling, or concurrency behavior.
42thread_startproc thread_start(thread: Thread, entry: proc) -> bool {Owns coordination, scheduling, or concurrency behavior.
61thread_spawnproc thread_spawn(name: string, entry: proc) -> Thread {Owns coordination, scheduling, or concurrency behavior.
68thread_current_idproc thread_current_id() -> int {Owns coordination, scheduling, or concurrency behavior.
73thread_nameproc thread_name(thread: Thread) -> string {Owns coordination, scheduling, or concurrency behavior.
78thread_set_nameproc thread_set_name(thread: Thread, name: string) -> bool {Owns coordination, scheduling, or concurrency behavior.
84thread_joinproc thread_join(thread: Thread) -> bool {Owns path semantics, traversal, or normalization.
97thread_join_timeoutproc thread_join_timeout(thread: Thread, timeout_ms: int) -> bool {Owns path semantics, traversal, or normalization.
112thread_detachproc thread_detach(thread: Thread) -> bool {Owns coordination, scheduling, or concurrency behavior.
123thread_is_aliveproc thread_is_alive(thread: Thread) -> bool {Owns coordination, scheduling, or concurrency behavior.
128thread_get_stateproc thread_get_state(thread: Thread) -> int {Owns coordination, scheduling, or concurrency behavior.
133thread_get_resultproc thread_get_result(thread: Thread) -> int {Owns coordination, scheduling, or concurrency behavior.
142thread_get_errorproc thread_get_error(thread: Thread) -> string {Owns coordination, scheduling, or concurrency behavior.
147thread_set_stack_sizeproc thread_set_stack_size(thread: Thread, size: int) -> bool {Owns coordination, scheduling, or concurrency behavior.
157thread_set_daemonproc thread_set_daemon(thread: Thread, is_daemon: bool) -> bool {Owns coordination, scheduling, or concurrency behavior.
163thread_set_priorityproc thread_set_priority(thread: Thread, priority: int) -> bool {Owns coordination, scheduling, or concurrency behavior.
169cpu_countproc cpu_count() -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
174thread_yieldproc thread_yield() -> bool {Owns coordination, scheduling, or concurrency behavior.
179thread_get_allproc thread_get_all() -> [Thread] {Owns coordination, scheduling, or concurrency behavior.
193thread_statsproc thread_stats() -> ThreadStats {Owns coordination, scheduling, or concurrency behavior.
206threadlocal_newproc threadlocal_new<T>() -> ThreadLocal<T> {Represents one top-level surface in the file contract and should be read as part of the module boundary.
215threadlocal_setproc threadlocal_set<T>(local: ThreadLocal<T>, value: T) -> bool {Owns a concrete data shape or the operations that maintain it.
220threadlocal_getproc threadlocal_get<T>(local: ThreadLocal<T>) -> T {Represents one top-level surface in the file contract and should be read as part of the module boundary.
232get_next_thread_idproc get_next_thread_id() -> int {Owns coordination, scheduling, or concurrency behavior.
237get_next_threadlocal_idproc get_next_threadlocal_id() -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
242sleep_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.
246timestamp_nowproc timestamp_now() -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.

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/thread.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/threadpool.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/threadpool.vitl316Shares the same family boundary but carries a distinct slice of responsibility.

Neighbor modules