Threads
A thread is a struct proc that shares three counted objects with others of its group: the address space (struct mm: page tables, heap top, VMAs and a lock for changing them), the descriptor table, and the signal dispositions. clone() shares what its flags say and fork() copies. - clone(): pthread_create's shape (VM, FILES, SIGHAND, THREAD, SETTLS, PARENT_SETTID, CHILD_CLEARTID) and posix_spawn's (VM, VFORK, a stack). - futex: WAIT, WAIT_BITSET with timeouts, WAKE, REQUEUE, CMP_REQUEUE, keyed by the word's kernel address so shared pages meet. set_tid_address keeps the word that exit zeroes and wakes, for pthread_join. - exit ends a thread; exit_group, a fatal signal, or the leader exiting ends them all. reapd frees exited threads; the leader is reaped by its parent once the rest are gone. getpid is the group, gettid the thread. - Stops and resumes reach every thread; other process signals the leader. - exec kills the other threads and unshares the dispositions. - No TLB shootdown, so pages unmapped from a shared address space are freed only once every CPU has reloaded CR3 or is idle. - procfs: /proc lists processes, task/ lists threads, comm, Threads:, Tgid. - The console honours VMIN 0 / VTIME (btop's input drain hung on it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
parent
2372806862
commit
f4d7f9100d
19 changed files with 1300 additions and 248 deletions
|
|
@ -32,10 +32,12 @@ sys_enable_linux_abi(void)
|
|||
addr_t
|
||||
sys_set_tid_address(void)
|
||||
{
|
||||
// The word zeroed and woken when this thread exits -- what pthread_join
|
||||
// waits on. It used to be *written*, with the tid, which is CHILD_SETTID's
|
||||
// job and not this one's.
|
||||
addr_t tidp;
|
||||
argaddr(0, &tidp);
|
||||
if (tidp)
|
||||
put_user(myproc()->pid, tidp);
|
||||
myproc()->clear_child_tid = tidp;
|
||||
return myproc()->pid;
|
||||
}
|
||||
|
||||
|
|
@ -46,12 +48,15 @@ addr_t sys_set_robust_list(void) { return 0; }
|
|||
addr_t
|
||||
sys_futex(void)
|
||||
{
|
||||
int op;
|
||||
addr_t uaddr, utime, uaddr2;
|
||||
int op, val, val3;
|
||||
argaddr(0, &uaddr);
|
||||
argint(1, &op);
|
||||
op &= ~(FUTEX_WAIT_PRIVATE - FUTEX_WAIT);
|
||||
if (op == FUTEX_WAKE || op == FUTEX_WAKE_PRIVATE)
|
||||
return 0;
|
||||
return -EAGAIN; // no blocking, musl retries
|
||||
argint(2, &val);
|
||||
argaddr(3, &utime);
|
||||
argaddr(4, &uaddr2);
|
||||
argint(5, &val3);
|
||||
return futex_op(uaddr, op, val, utime, uaddr2, val3);
|
||||
}
|
||||
|
||||
// arch_prctl: save FS_BASE for TLS.
|
||||
|
|
|
|||
Loading…
Reference in a new issue