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

  • 17Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Thread Basics and Motivation

What is the primary motivation for using threads in a process?

17 questions

  1. 1

    What is the primary motivation for using threads in a process?

    Model answer

    Threads allow a process to perform multiple tasks concurrently, such as handling user input and updating the display simultaneously.

    Explanation

    Threads enable a process to run multiple execution paths at once, improving responsiveness and performance, especially on multicore systems.

  2. 2

    List three examples of applications that benefit from threading.

    Model answer

    Games, video rendering, and network traffic handling benefit from threading.

    Explanation

    These applications can use threads for tasks like keyboard input, screen updates, and background processing.

  3. 3

    How do threads differ from processes in terms of resource usage?

    Model answer

    Threads are lighter than processes because they share the same code, data, and files, reducing overhead in creation and management.

    Explanation

    Creating a thread involves sharing existing resources, whereas a process requires its own separate address space and system resources.

  4. 4

    Explain why inter-thread communication is typically more efficient than inter-process communication.

    Model answer

    Threads share the same memory space, so they can communicate directly without the overhead of message passing required for processes.

    Explanation

    Since threads within a process share data, they can read and write the same variables, avoiding the need for system calls for IPC.

  5. 5

    What is the difference between concurrency and parallelism?

    Model answer

    Concurrency involves multiple tasks making progress over time (e.g., via time-sharing), while parallelism involves multiple tasks executing simultaneously (e.g., on multiple cores).

    Explanation

    Concurrency is about interleaving tasks, whereas parallelism is about true simultaneous execution, requiring hardware support.

  6. 6

    Define data parallelism and give an example.

    Model answer

    Data parallelism splits data into chunks and processes each chunk in parallel; e.g., rendering an image by dividing it into sections across threads.

    Explanation

    In data parallelism, the same operation is applied to different subsets of data simultaneously.

  7. 7

    Define task parallelism and give an example.

    Model answer

    Task parallelism runs different tasks concurrently; e.g., a word processor running editing, spell-checking, and display threads simultaneously.

    Explanation

    In task parallelism, each thread performs a distinct operation, often on shared data.

  8. 8

    State Amdahl's Law in words.

    Model answer

    Amdahl's Law states that the speedup of a program is limited by the fraction of its execution that must be performed sequentially.

    Explanation

    Even with many cores, the serial part (S) becomes a bottleneck, preventing linear speedup.

  9. 9

    If an application is 75% parallelizable and 25% serial, what is the maximum speedup when doubling the number of cores from 1 to 2?

    Model answer

    The speedup is approximately 1.6 times.

    Explanation

    Using Amdahl's Law: speedup =1(1−P)+PN=10.25+0.752=10.25+0.375=10.625=1.6= \frac{1}{(1 - P) + \frac{P}{N}} = \frac{1}{0.25 + \frac{0.75}{2}} = \frac{1}{0.25 + 0.375} = \frac{1}{0.625} = 1.6=(1−P)+NP​1​=0.25+20.75​1​=0.25+0.3751​=0.6251​=1.6.

  10. 10

    Name three commonly used thread libraries.

    Model answer

    POSIX threads (Pthreads), Windows threads, and Java threads.

    Explanation

    Pthreads are used in Unix-like systems, Windows has its own API, and Java provides built-in threading support.

  11. 11

    Describe the many-to-one threading model and its main drawback.

    Model answer

    Many user threads map to a single kernel thread; if any user thread blocks, all threads in the process block, preventing parallelism.

    Explanation

    This model is inefficient for parallel execution and is rarely used in modern systems.

  12. 12

    Describe the one-to-one threading model and name an operating system that uses it.

    Model answer

    Each user thread maps to a single kernel thread, allowing parallelism; used by Windows and Linux.

    Explanation

    This model provides true concurrency but may limit the number of threads due to kernel overhead.

  13. 13

    What is the two-level threading model?

    Model answer

    It combines many-to-many mapping with the ability to bind specific user threads to dedicated kernel threads.

    Explanation

    This offers flexibility: many user threads can be multiplexed onto fewer kernel threads, while critical threads get a dedicated kernel thread.

  14. 14

    What components make up a thread block (thread context)?

    Model answer

    A thread context includes a thread ID, a set of registers, a stack, and scheduling/ synchronization information.

    Explanation

    These components are stored by the operating system to manage thread execution and context switching.

  15. 15

    How does Windows represent a thread in the kernel?

    Model answer

    A Windows thread is represented by an executive thread structure that points to a kernel thread block containing scheduling, synchronization, and stack data, which then points to the user-space thread.

    Explanation

    This layered structure allows the kernel to manage thread execution independently of user code.

  16. 16

    How does Linux implement threads?

    Model answer

    Linux treats threads as tasks and uses the clone() system call to create new tasks that can share resources like memory, files, and signal handlers.

    Explanation

    clone() allows selective sharing by passing flags, enabling lightweight thread creation compared to forking a new process.

  17. 17

    What is the purpose of the clone() system call in Linux?

    Model answer

    It creates a new task (thread) that shares the same code, data, and files as the parent, but can have its own stack and registers.

    Explanation

    Clone is versatile; depending on flags, it can create a traditional process or a thread sharing various resources.

1 of 17
Question 1 of 17

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent