nx_thread.nx
buildroot/runtime/nx_thread.nx
about
nx_thread.nx -- clone(2)-based thread creation (CLONE_VM, CLONE_FS,
CLONE_FILES, CLONE_SIGHAND, CLONE_THREAD).
A "thread" on Linux is just a process that shares its parent's
address space + file table + signal handlers. clone() with the
right flags creates one. This module exposes a focused API on
top of the raw syscall.
Key constraint: the new thread starts at the function specified
by `entry` with stack pointer set to `stack_top`. Caller must
allocate the stack themselves (typically 64 KiB - 8 MiB).
We don't pass the function via a function pointer (NishiLang has
no first-class func type) -- caller passes the symbol address as
i64 they obtained out-of-band. When NishiLang grows func types,
the API takes a typed callback.
Today the sim is single-threaded. Calling nx_thread_spawn
against the host kernel will succeed (real threads are created)
but the in-process simulator can't observe them. When SMP lands
in nx_rv64_sim, the simulated CPU array maps onto host threads
via this primitive.
Pairs with nx_atom (atomic state across threads) + nx_mutex
(futex-based blocking) + nx_proc (parent process abstraction).
dependencies 2 imports · 16 importers
diagram shows first 10 each side; +0 more imports, +6 more importers in the complete lists below.
imports: nx_syscalls.nxnx_proc.nx
imported by: nx_chan.nxnx_chan_mpmc_test.nxnx_mutex_race_test.nxnx_natbw_mt.nxnx_natfu_probe.nxnx_net_chan_blob_test.nxnx_net_chan_test.nxnx_pipeline.nxnx_pteam.nxnx_q4k_gemm_mt.nxnx_remote_worker.nxnx_rpc_test.nxnx_socket_pingpong_test.nxnx_thread_pool.nxnx_thread_pool_test.nxnx_thread_spawn_test.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 35 | const NX_MAGIC_65536: i64 = 65536 |
| 36 | const NX_MAGIC_262144: i64 = 262144 |
| 40 | const NX_THREAD_CLONE_FLAGS: i64 = 0x100 // CLONE_VM |
| 41 | const NX_THREAD_FS: i64 = 0x200 // CLONE_FS |
| 42 | const NX_THREAD_FILES: i64 = 0x400 // CLONE_FILES |
| 43 | const NX_THREAD_SIGHAND: i64 = 0x800 // CLONE_SIGHAND |
| 44 | const NX_THREAD_THREAD: i64 = 0x10000 // CLONE_THREAD |
| 45 | const NX_THREAD_SETTLS: i64 = 0x80000 // CLONE_SETTLS |
| 46 | const NX_THREAD_PARENT_TID: i64 = 0x100000 // CLONE_PARENT_SETTID |
| 47 | const NX_THREAD_CHILD_TID: i64 = 0x200000 // CLONE_CHILD_CLEARTID |
| 51 | const NX_THREAD_DEFAULT_FLAGS: i64 = 0x100 // CLONE_VM |
functions
| 58 | func nx_thread_spawn_raw(flags: i64, stack_top: i64) -> i64 |
| 73 | func nx_thread_spawn(entry: i64, ctx: i64, stack_size: i64) -> i64 |
| 84 | func nx_thread_spawn_fn(entry: func(*u8) -> i64, ctx: *u8, stack_size: i64) -> i64 |
| 95 | func sys_thread_create(argptr: i64) -> i64 |
| 101 | func nx_thread_self() -> i64 called by 1: main |
| 107 | func nx_thread_yield() -> i64 |
| 113 | func nx_thread_exit(code: i64) -> i64 |
| 119 | func main() -> i64 |