Skip to main content

Module threads_scheme

Module threads_scheme 

Source
Expand description

ThreadsScheme : Plan 9 style /thread control files.

Exposes the userspace thread API as filesystem operations. All lifecycle work is forwarded to crate::process::thread_ops, the exact same internals as SYS_THREAD_CREATE/JOIN/EXIT, so both entry points share one implementation (single reap loop, single validation rules).

ยงFile layout

/thread/            directory: TIDs of the calling process' threads
  create    write   32-byte ThreadCreateRequest -> read back TID (u32 LE)
  join/<tid>read    blocks until <tid> exits -> exit code (i32 LE)
                    EINVAL self-join, ENOENT absent/already-joined
                    (=> a second open of join/<tid> fails; documented)
  exit      write   exit code (i32 LE); kills current thread, no return
  current   read    caller's TID (u32 LE), resolved at read time
  yield     read    sched_yield; fd shareable across threads
  kill/<tid>open    terminates <tid>; ESRCH absent, EPERM cross-process
  stats     read    kernel-owned stack counters ("allocated N", "active M")

Structsยง

ThreadsScheme

Enumsยง

Op ๐Ÿ”’
Operation encoded in the high bits of a file_id.
OpState ๐Ÿ”’
Per-fd state retained between open/write/read.

Constantsยง

THREAD_CREATE_REQ_LEN ๐Ÿ”’
Binary protocol for /thread/create writes.

Functionsยง

init_threads_scheme
Convenience constructor matching the other scheme registration sites.
itoa_u32 ๐Ÿ”’
Minimal decimal formatter (no formatting machinery in hot paths).
op_of ๐Ÿ”’
serve_string ๐Ÿ”’
Serve string content honoring read offsets (procfs pattern).