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.
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
- Purpose
- Taxonomy
- Implementation profile
- Top-level API inventory
- Position in family
- Declaration map
- Representative signatures
- How to use this module
- User example
- Keyword coverage
- Source shape
- Source landmarks
- Source organization
- Complete API catalog
- Integration boundaries
- Composition guidance
- Relationship table
- Neighbor modules
Overview
| Field | Value |
|---|---|
| Path | threading/thread.vitl |
| Family | threading |
| Kind | public stdlib surface |
| Line count | 248 |
| Declared procedures | 27 |
| Declared forms/picks | 3 |
`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.
| Signal | Count | What it suggests |
|---|---|---|
if | 7 | Branching density and local decision-making. |
while | 2 | Loop-heavy or iterative implementation style. |
for | 2 | Collection-style traversal at source level. |
match | 0 | Variant-driven branching or grammar-style decoding. |
let | 7 | Local state and intermediate value density. |
give | 33 | Number of explicit exit points and result shaping. |
Top-level API inventory
| Surface | Items |
|---|---|
| Procedures | thread_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 |
| Forms | Thread, ThreadLocal, ThreadStats |
| Picks | none declared at top level |
| Constants | THREAD_ID_COUNTER, THREADLOCAL_ID_COUNTER |
| Exports | none 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.
| Line | Name | Kind | Role |
|---|---|---|---|
| 1 | vitte/stdlib/threading/thread | space | Declares the namespace that anchors this file in the stdlib tree. |
| 5 | Thread | form | Introduces a structured data shape that other procedures can exchange. |
| 18 | ThreadLocal | form | Introduces a structured data shape that other procedures can exchange. |
| 24 | thread_new | proc | Owns coordination, scheduling, or concurrency behavior. |
| 42 | thread_start | proc | Owns coordination, scheduling, or concurrency behavior. |
| 61 | thread_spawn | proc | Owns coordination, scheduling, or concurrency behavior. |
| 68 | thread_current_id | proc | Owns coordination, scheduling, or concurrency behavior. |
| 73 | thread_name | proc | Owns coordination, scheduling, or concurrency behavior. |
| 78 | thread_set_name | proc | Owns coordination, scheduling, or concurrency behavior. |
| 84 | thread_join | proc | Owns path semantics, traversal, or normalization. |
| 97 | thread_join_timeout | proc | Owns path semantics, traversal, or normalization. |
| 112 | thread_detach | proc | Owns coordination, scheduling, or concurrency behavior. |
| 123 | thread_is_alive | proc | Owns coordination, scheduling, or concurrency behavior. |
| 128 | thread_get_state | proc | Owns coordination, scheduling, or concurrency behavior. |
| 133 | thread_get_result | proc | Owns coordination, scheduling, or concurrency behavior. |
| 142 | thread_get_error | proc | Owns coordination, scheduling, or concurrency behavior. |
| 147 | thread_set_stack_size | proc | Owns coordination, scheduling, or concurrency behavior. |
| 157 | thread_set_daemon | proc | Owns coordination, scheduling, or concurrency behavior. |
| 163 | thread_set_priority | proc | Owns coordination, scheduling, or concurrency behavior. |
| 169 | cpu_count | proc | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 174 | thread_yield | proc | Owns coordination, scheduling, or concurrency behavior. |
| 179 | thread_get_all | proc | Owns coordination, scheduling, or concurrency behavior. |
| 185 | ThreadStats | form | Introduces a structured data shape that other procedures can exchange. |
| 193 | thread_stats | proc | Owns coordination, scheduling, or concurrency behavior. |
| 206 | threadlocal_new | proc | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 215 | threadlocal_set | proc | Owns a concrete data shape or the operations that maintain it. |
| 220 | threadlocal_get | proc | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 229 | THREAD_ID_COUNTER | const | Defines a named constant reused across the module. |
| 230 | THREADLOCAL_ID_COUNTER | const | Defines a named constant reused across the module. |
| 232 | get_next_thread_id | proc | Owns coordination, scheduling, or concurrency behavior. |
| 237 | get_next_threadlocal_id | proc | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 242 | sleep_ms | proc | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 246 | timestamp_now | proc | Represents 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.
- Read
spaceand top-level imports first so the ownership boundary ofthreading/thread.vitlis explicit. - Scan constants before procedures; they often encode precision, limits, or policy assumptions that explain later behavior.
- Read declared forms and picks before algorithms so the data vocabulary is stable in your head.
- Traverse procedures in source order; the early helpers usually explain the naming and numeric conventions used later.
- 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.
| Keyword | Present in module source | Used in generated user example |
|---|---|---|
space | yes | yes |
const | yes | yes |
form | yes | yes |
proc | yes | yes |
let | yes | yes |
set | yes | no |
if | yes | yes |
while | yes | no |
for | yes | no |
give | yes | yes |
entry | yes | no |
true | yes | yes |
false | yes | yes |
and | yes | yes |
not | yes | yes |
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
| Line | Name | Signature | Role |
|---|---|---|---|
| 229 | THREAD_ID_COUNTER | const THREAD_ID_COUNTER: int = 0 | Defines a named constant reused across the module. |
| 230 | THREADLOCAL_ID_COUNTER | const THREADLOCAL_ID_COUNTER: int = 0 | Defines a named constant reused across the module. |
Data surfaces
| Line | Name | Signature | Role |
|---|---|---|---|
| 5 | Thread | form Thread { | Introduces a structured data shape that other procedures can exchange. |
| 18 | ThreadLocal | form ThreadLocal<T> { | Introduces a structured data shape that other procedures can exchange. |
| 185 | ThreadStats | form ThreadStats { | Introduces a structured data shape that other procedures can exchange. |
Procedures
| Line | Name | Signature | Role |
|---|---|---|---|
| 24 | thread_new | proc thread_new(name: string) -> Thread { | Owns coordination, scheduling, or concurrency behavior. |
| 42 | thread_start | proc thread_start(thread: Thread, entry: proc) -> bool { | Owns coordination, scheduling, or concurrency behavior. |
| 61 | thread_spawn | proc thread_spawn(name: string, entry: proc) -> Thread { | Owns coordination, scheduling, or concurrency behavior. |
| 68 | thread_current_id | proc thread_current_id() -> int { | Owns coordination, scheduling, or concurrency behavior. |
| 73 | thread_name | proc thread_name(thread: Thread) -> string { | Owns coordination, scheduling, or concurrency behavior. |
| 78 | thread_set_name | proc thread_set_name(thread: Thread, name: string) -> bool { | Owns coordination, scheduling, or concurrency behavior. |
| 84 | thread_join | proc thread_join(thread: Thread) -> bool { | Owns path semantics, traversal, or normalization. |
| 97 | thread_join_timeout | proc thread_join_timeout(thread: Thread, timeout_ms: int) -> bool { | Owns path semantics, traversal, or normalization. |
| 112 | thread_detach | proc thread_detach(thread: Thread) -> bool { | Owns coordination, scheduling, or concurrency behavior. |
| 123 | thread_is_alive | proc thread_is_alive(thread: Thread) -> bool { | Owns coordination, scheduling, or concurrency behavior. |
| 128 | thread_get_state | proc thread_get_state(thread: Thread) -> int { | Owns coordination, scheduling, or concurrency behavior. |
| 133 | thread_get_result | proc thread_get_result(thread: Thread) -> int { | Owns coordination, scheduling, or concurrency behavior. |
| 142 | thread_get_error | proc thread_get_error(thread: Thread) -> string { | Owns coordination, scheduling, or concurrency behavior. |
| 147 | thread_set_stack_size | proc thread_set_stack_size(thread: Thread, size: int) -> bool { | Owns coordination, scheduling, or concurrency behavior. |
| 157 | thread_set_daemon | proc thread_set_daemon(thread: Thread, is_daemon: bool) -> bool { | Owns coordination, scheduling, or concurrency behavior. |
| 163 | thread_set_priority | proc thread_set_priority(thread: Thread, priority: int) -> bool { | Owns coordination, scheduling, or concurrency behavior. |
| 169 | cpu_count | proc cpu_count() -> int { | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 174 | thread_yield | proc thread_yield() -> bool { | Owns coordination, scheduling, or concurrency behavior. |
| 179 | thread_get_all | proc thread_get_all() -> [Thread] { | Owns coordination, scheduling, or concurrency behavior. |
| 193 | thread_stats | proc thread_stats() -> ThreadStats { | Owns coordination, scheduling, or concurrency behavior. |
| 206 | threadlocal_new | proc threadlocal_new<T>() -> ThreadLocal<T> { | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 215 | threadlocal_set | proc threadlocal_set<T>(local: ThreadLocal<T>, value: T) -> bool { | Owns a concrete data shape or the operations that maintain it. |
| 220 | threadlocal_get | proc 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. |
| 232 | get_next_thread_id | proc get_next_thread_id() -> int { | Owns coordination, scheduling, or concurrency behavior. |
| 237 | get_next_threadlocal_id | proc get_next_threadlocal_id() -> int { | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 242 | sleep_ms | proc sleep_ms(ms: int) -> bool { | Represents one top-level surface in the file contract and should be read as part of the module boundary. |
| 246 | timestamp_now | proc 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.vitlwhen 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.vitlbefore 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.
| Neighbor | Procedures | Data surfaces | Why compare it |
|---|---|---|---|
threading/mutex.vitl | 30 | 4 | Shares the same family boundary but carries a distinct slice of responsibility. |
threading/threadpool.vitl | 31 | 6 | Shares the same family boundary but carries a distinct slice of responsibility. |