1. Home
  2. Explore
  3. Computer Science
  4. Threads Lecture Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Threads Lecture Overview

  • 23Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Thread Basics
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is a thread?

Tap to flipClick to flipspace

A thread is a part of a process that can run multiple pieces of code at the same time. It shares the process's code, data, and files but has its own register set and stack.

Or swipe the card

23 cards

  1. What is a thread?

    A thread is a part of a process that can run multiple pieces of code at the same time. It shares the process's code, data, and files but has its own register set and stack.

  2. How does a thread differ from a process?

    A process has its own code, data, and files; a thread is part of a process and shares those resources. Threads are more lightweight and have less overhead than processes.

  3. Why are threads considered less resource-heavy than processes?

    Threads share code, data, and files with the parent process, so they don't require duplicating these resources. This reduces overhead in terms of CPU time, memory, and other metrics.

  4. What are the benefits of using threads?

    Threads enable parallelism, improve responsiveness, share resources efficiently, and allow a process to take advantage of multi-core hardware for faster execution.

  5. What is concurrency?

    Concurrency is when multiple tasks make progress over time, but only one runs at any instant (e.g., time-sharing system).

  6. What is parallelism?

    Parallelism is when the system runs more than one thing at the same time, typically on multi-core or multiprocessor systems.

  7. What is data parallelism?

    Data parallelism splits data into chunks and distributes each chunk to multiple threads that perform the same operation, then merges the results.

  8. What is task parallelism?

    Task parallelism involves running different tasks (e.g., editing, spell-checking, displaying) at the same time, each as a separate thread.

  9. What does Amdahl's law describe?

    Amdahl's law states that the speedup of a system is limited by the serial portion of the workload. Speedup = 1 / (S + (1-S)/N), where S is the serial fraction and N is the number of cores.

  10. If 25% of an application is serial and 75% parallel, what speedup is achieved by doubling cores from 1 to 2?

    Approximately 1.6 times faster.

  11. What is the role of thread libraries?

    Thread libraries provide an API for programmers to create and manage threads. Examples include POSIX Pthreads (Unix/Linux), Windows threads, and Java threads.

  12. What is a user thread?

    A user thread is a thread created by the programmer using a thread library. It is managed at the user level without kernel intervention.

  13. What is a kernel thread?

    A kernel thread is a thread that is managed directly by the operating system kernel. It is the actual unit scheduled on the CPU.

  14. Describe the many-to-one thread mapping model.

    Many user threads are mapped to a single kernel thread. If any user thread blocks, all are blocked, and true parallelism is not possible.

  15. Describe the one-to-one thread mapping model.

    Each user thread maps to a single kernel thread. This allows parallelism and is used by Windows and Linux.

  16. Describe the many-to-many thread mapping model.

    Many user threads are multiplexed onto many kernel threads. The OS manages the number of kernel threads. More complex but flexible.

  17. What is the two-level thread model?

    It combines many-to-many and one-to-one: most threads are many-to-many, but some threads can be bound to a single kernel thread for special treatment.

  18. What is Pthreads?

    Pthreads is a POSIX standard API for thread creation and management, commonly used on Unix/Linux systems (including macOS).

  19. How does Windows implement threads?

    Windows uses a one-to-one model. Each thread has a thread ID, a set of registers, a stack, and a thread context. The structure includes an executive thread block (ETHREAD) and a kernel thread block (KTHREAD).

  20. What is thread context?

    Thread context is the state of a thread, including registers, program counter, and stack. It is used to save and restore thread state during context switches.

  21. How does Linux implement threads?

    Linux treats threads as tasks and uses the clone() system call, which allows sharing of code, data, files, signal handlers, etc., and creates a new task with its own stack.

  22. What is a system call?

    A system call is an interface between a user process and the operating system. It allows user programs to request services (e.g., disk I/O, display updates, mouse clicks) from the OS.

  23. Give an example of a system call.

    Opening a file (e.g., reading 'fred.txt' from a network share) is a system call. The OS performs the low-level operations and returns the data to the user process.

Card 1 of 23
Card 1 of 23

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent