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
|
|
@ -79,12 +79,12 @@ do_poll(struct pollfd *fds, int nfds, int timeout_ticks)
|
|||
fds[i].revents = 0;
|
||||
if (fds[i].fd < 0)
|
||||
continue; // negative fd: ignore, per poll(2)
|
||||
if (fds[i].fd >= NOFILE || !myproc()->ofile[fds[i].fd]) {
|
||||
if (fds[i].fd >= NOFILE || !myproc()->files->ofile[fds[i].fd]) {
|
||||
fds[i].revents = POLLNVAL;
|
||||
nready++;
|
||||
continue;
|
||||
}
|
||||
int rev = file_poll(myproc()->ofile[fds[i].fd], fds[i].events);
|
||||
int rev = file_poll(myproc()->files->ofile[fds[i].fd], fds[i].events);
|
||||
if (rev) {
|
||||
fds[i].revents = (short)rev;
|
||||
nready++;
|
||||
|
|
@ -217,7 +217,7 @@ sys_select(void)
|
|||
int want_w = fdset_isset(wr, fd);
|
||||
if (!want_r && !want_w)
|
||||
continue;
|
||||
struct file *f = myproc()->ofile[fd];
|
||||
struct file *f = myproc()->files->ofile[fd];
|
||||
if (!f)
|
||||
return -EBADF;
|
||||
int rev = file_poll(f, (want_r ? POLLIN : 0) | (want_w ? POLLOUT : 0));
|
||||
|
|
@ -292,7 +292,7 @@ sys_pselect6(void)
|
|||
int want_w = fdset_isset(wr, fd);
|
||||
if (!want_r && !want_w)
|
||||
continue;
|
||||
struct file *f = myproc()->ofile[fd];
|
||||
struct file *f = myproc()->files->ofile[fd];
|
||||
if (!f)
|
||||
return -EBADF;
|
||||
int rev = file_poll(f, (want_r ? POLLIN : 0) | (want_w ? POLLOUT : 0));
|
||||
|
|
|
|||
Loading…
Reference in a new issue