عجفت الغور

operating systems

Tags: computers

Threads

  • Similar to a linux process that always run in the same memory

    • own instruction pointer, and can be scheduled on different CPU’s and executing different things on the same program
    • shares the process structure (execpt stacks)
    • linux threads have their own pid
    • solaris is completely thread based
    • in linux, a thread is a prococess without a thread
    • created with the clone() system call
    • treat as one process in some games, uses the thread group
    • getpid() will tell you some info
    • syn and locks!
    • threads tend to be pretty fast, usually an async that does stuff in the background, and never switches off the task running state, spinning is TASK_RUN, but it’s not waiting on IO but rather a lock
    • biggest reason to use over a fork is because you can do the same memory
  • linux kernel only uses lightweight processes, or threads.

    • Threads use libc to transition to kernel space, but posix threads originate from libc and libpthread. Note that the kernel only uses LWPs. However, at the kernel layer, since a userspace thread maps to a lwp, it doesn’t really matter
  • Debugger commands
    • GDB
      • info threads -> list threads
      • thread <n> -> switches between threads
      • thread apply all bt -> backtraces
    • LLDB
      • thread list
      • thread select 1
      • thread backtrace all~/~bt all
  • Thread stacks
    • each thread has its own stack to store data, and we can dump it like normal

    • Stack tracing a thread is when a function A calls function B, and function B has a return address to where function A called it.

  • Symbol files
    • Symbols provide mappings between memory address ranges and associated symbol names, if you don’t have the symbols, you just have the current function

Concurrent Forward Progress

  • If your threads are preemptible, it’s possible that they, while being preempted for another task, might come back to having less resources than before, since the preemption task might take a different amount of resources. How do we fix this?

NixOS