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

  • 29Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Thread Fundamentals

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

29 questions

  1. 1

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

    1. A

      To perform multiple tasks concurrently within a single process

    2. B

      To reduce the need for hardware upgrades

    3. C

      To simplify programming by eliminating system calls

    4. D

      To increase the number of processes running simultaneously

    Correct answer
    A

    To perform multiple tasks concurrently within a single process

    Explanation

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

  2. 2

    Which of the following is an example of using threads in a game?

    1. A

      Running the game as a background process

    2. B

      Disabling sound to improve performance

    3. C

      Having separate threads for keyboard input and screen updates

    4. D

      Using a single thread to load the entire game

    Correct answer
    C

    Having separate threads for keyboard input and screen updates

    Explanation

    In a game, threads can handle keyboard input and screen updates concurrently, avoiding the need to alternate between tasks.

  3. 3

    Threads can be used to run the same algorithm on different data sets in parallel. This is commonly done for which task?

    1. A

      Rendering a video

    2. B

      Updating a network connection

    3. C

      Managing file I/O

    4. D

      Spell checking a document

    Correct answer
    A

    Rendering a video

    Explanation

    For rendering a video, the same algorithm can be applied to different parts of the data in parallel using multiple threads.

  4. 4

    Which of the following applications would benefit from multithreading?

    1. A

      A word processor with real-time spell checking

    2. B

      A simple calculator that performs one operation at a time

    3. C

      A command-line tool that reads a file and exits

    4. D

      A static web page displaying text

    Correct answer
    A

    A word processor with real-time spell checking

    Explanation

    Real-time spell checking benefits from a background thread that continuously checks grammar while the user types.

  5. 5

    What must the operating system provide for threads to be used by applications?

    1. A

      A new file system

    2. B

      A dedicated processor for each thread

    3. C

      Services and an API for creating and managing threads

    4. D

      Automatic thread creation for every program

    Correct answer
    C

    Services and an API for creating and managing threads

    Explanation

    The OS must offer thread services via an API, which applications can call to create and manage threads.

  6. 6

    Why are most modern operating systems multithreaded?

    1. A

      Because threads are easier to program than processes

    2. B

      Because threads consume more memory than processes

    3. C

      Because they are designed to run on single-core processors

    4. D

      Because modern hardware often has multiple cores or processors

    Correct answer
    D

    Because modern hardware often has multiple cores or processors

    Explanation

    Modern hardware with multiple cores or processors allows multithreaded processes to run in parallel, improving performance.

  7. 7

    How does the operating system adapt to new hardware such as a wireless trackball?

    1. A

      By adding a device driver to support the new hardware

    2. B

      By replacing the entire kernel

    3. C

      By rewriting all system calls

    4. D

      By disabling existing hardware support

    Correct answer
    A

    By adding a device driver to support the new hardware

    Explanation

    The OS evolves by adding drivers to support new hardware, such as Bluetooth and additional features like scroll wheels.

  8. 8

    What is a key advantage of using threads over processes for concurrent tasks?

    1. A

      Threads cannot share memory, making them more secure

    2. B

      Threads require separate memory spaces for each task

    3. C

      Threads are easier to debug than processes

    4. D

      Threads are less resource-heavy because they share the code, data, and files of the parent process

    Correct answer
    D

    Threads are less resource-heavy because they share the code, data, and files of the parent process

    Explanation

    Threads share the same resources (code, data, files) as the parent process, making them lighter than creating separate processes.

  9. 9

    In the client-server approach to threads, who creates the new thread?

    1. A

      The kernel

    2. B

      The user

    3. C

      The hardware

    4. D

      The client process

    Correct answer
    A

    The kernel

    Explanation

    The kernel creates new threads in response to client requests, acting as the server.

  10. 10

    How does multithreading help maintain responsiveness in a word processor?

    1. A

      By running all tasks in a single thread

    2. B

      By blocking user input until calculations are complete

    3. C

      By allowing a background thread to continue spell checking while the UI remains responsive

    4. D

      By using multiple processes for each task

    Correct answer
    C

    By allowing a background thread to continue spell checking while the UI remains responsive

    Explanation

    The spell check thread runs in the background, so the UI thread remains responsive to user input.

  11. 11

    Why is inter-thread communication cheaper than inter-process communication?

    1. A

      Threads require encryption for all communication

    2. B

      Threads use separate network connections

    3. C

      Threads share the same memory space, so they can access shared data directly

    4. D

      Threads rely on message passing, which is efficient

    Correct answer
    C

    Threads share the same memory space, so they can access shared data directly

    Explanation

    Since threads share memory, they can directly access shared data without the overhead of message passing.

  12. 12

    What is a challenge when programming with threads?

    1. A

      Threads eliminate the need for error handling

    2. B

      Threads automatically synchronize access to shared data

    3. C

      Managing shared data and avoiding race conditions is difficult

    4. D

      Threads cannot be created dynamically

    Correct answer
    C

    Managing shared data and avoiding race conditions is difficult

    Explanation

    One of the main challenges is synchronizing access to shared data to prevent race conditions.

  13. 13

    What is the difference between parallelism and concurrency?

    1. A

      Concurrency is the same as parallelism

    2. B

      Parallelism means multiple tasks make progress but only one at a time; concurrency means tasks run simultaneously

    3. C

      Parallelism means tasks run simultaneously; concurrency means multiple tasks make progress but are interleaved

    4. D

      Parallelism is only possible on single-core systems

    Correct answer
    C

    Parallelism means tasks run simultaneously; concurrency means multiple tasks make progress but are interleaved

    Explanation

    Parallelism requires multiple cores and runs tasks at the same time; concurrency allows multiple tasks to make progress by interleaving execution.

  14. 14

    What is data parallelism?

    1. A

      Executing the same task on multiple datasets sequentially

    2. B

      Running different tasks on the same data

    3. C

      Splitting data into chunks and processing each chunk on a different core

    4. D

      Using a single thread to process all data sequentially

    Correct answer
    C

    Splitting data into chunks and processing each chunk on a different core

    Explanation

    Data parallelism divides data into chunks and processes each chunk in parallel, often using the same algorithm.

  15. 15

    What is task parallelism?

    1. A

      Running different tasks (e.g., editing and spell checking) simultaneously

    2. B

      Splitting data and processing it in parallel

    3. C

      Executing tasks one after another on different cores

    4. D

      Running the same task on different data sets

    Correct answer
    A

    Running different tasks (e.g., editing and spell checking) simultaneously

    Explanation

    Task parallelism involves executing different tasks concurrently, such as editing, spell checking, and displaying.

  16. 16

    What hardware support is needed for threads to run in parallel?

    1. A

      A single fast processor

    2. B

      Very large hard drives

    3. C

      A high-speed network interface

    4. D

      Multiple sets of registers and stacks

    Correct answer
    D

    Multiple sets of registers and stacks

    Explanation

    For threads to run in parallel, the hardware must provide multiple registers and stacks to keep each thread's context.

  17. 17

    What does 'thread context' refer to?

    1. A

      The thread's name and identifier

    2. B

      The state of the thread, including registers and stack

    3. C

      The thread's priority level

    4. D

      The thread's associated file descriptors

    Correct answer
    B

    The state of the thread, including registers and stack

    Explanation

    Thread context includes the registers, stack, and other execution state needed to resume the thread.

  18. 18

    According to Amdahl's Law, what limits the speedup from adding more cores?

    1. A

      The amount of memory available

    2. B

      The serial portion of the application

    3. C

      The clock speed of the processor

    4. D

      The number of threads in a process

    Correct answer
    B

    The serial portion of the application

    Explanation

    Amdahl's Law states that speedup is limited by the fraction of the application that must be executed sequentially.

  19. 19

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

    1. A

      1.25 times

    2. B

      2.0 times

    3. C

      1.6 times

    4. D

      1.33 times

    Correct answer
    C

    1.6 times

    Explanation

    Using Amdahl's Law: speedup =1/(0.25+0.75/2)=1/(0.25+0.375)=1/0.625=1.6= 1 / (0.25 + 0.75/2) = 1 / (0.25 + 0.375) = 1 / 0.625 = 1.6=1/(0.25+0.75/2)=1/(0.25+0.375)=1/0.625=1.6.

  20. 20

    What is the main drawback of the many-to-one thread model?

    1. A

      If one user thread blocks, all user threads in the process block

    2. B

      It is only available in Linux

    3. C

      It requires many kernel threads

    4. D

      It provides true parallelism

    Correct answer
    A

    If one user thread blocks, all user threads in the process block

    Explanation

    In the many-to-one model, all user threads are mapped to a single kernel thread, so if one blocks, the entire process blocks.

  21. 21

    Which thread model maps each user thread to a separate kernel thread?

    1. A

      One-to-one

    2. B

      Many-to-many

    3. C

      Two-level

    4. D

      Many-to-one

    Correct answer
    A

    One-to-one

    Explanation

    The one-to-one model creates one kernel thread for each user thread, allowing true parallelism.

  22. 22

    Which operating systems use the one-to-one thread model?

    1. A

      Unix and BSD

    2. B

      RTOS and Embedded systems

    3. C

      macOS and Android

    4. D

      Windows and Linux

    Correct answer
    D

    Windows and Linux

    Explanation

    Windows and Linux both implement the one-to-one model.

  23. 23

    What is a characteristic of the many-to-many thread model?

    1. A

      It does not allow user-level threads to be created

    2. B

      It binds each user thread to a specific kernel thread

    3. C

      The number of kernel threads can be less than, equal to, or greater than the number of user threads

    4. D

      It requires all threads to run on a single core

    Correct answer
    C

    The number of kernel threads can be less than, equal to, or greater than the number of user threads

    Explanation

    In the many-to-many model, the OS manages user threads and kernel threads, allowing flexible mapping.

  24. 24

    How does the two-level thread model extend the many-to-many model?

    1. A

      It eliminates user-level threads entirely

    2. B

      It permits some user threads to be bound to specific kernel threads (one-to-one), while others are handled many-to-many

    3. C

      It allows only one kernel thread per process

    4. D

      It requires all threads to be in kernel space

    Correct answer
    B

    It permits some user threads to be bound to specific kernel threads (one-to-one), while others are handled many-to-many

    Explanation

    The two-level model combines many-to-many with the ability to bind critical threads to dedicated kernel threads.

  25. 25

    Which of the following is a standard thread library for Unix-based systems?

    1. A

      MFC Threads

    2. B

      Windows Threads

    3. C

      Java Threads

    4. D

      Pthreads (POSIX threads)

    Correct answer
    D

    Pthreads (POSIX threads)

    Explanation

    Pthreads (POSIX threads) is the standard on Unix/Linux systems.

  26. 26

    In Windows, what structure stores the thread's context (registers and stack)?

    1. A

      Thread Context Block

    2. B

      Kernel Thread

    3. C

      Process Control Block

    4. D

      Executive Thread

    Correct answer
    B

    Kernel Thread

    Explanation

    The kernel thread structure holds the scheduling information, synchronization data, and the thread's stack (context).

  27. 27

    In Linux, how are threads created and how do they share resources?

    1. A

      Using the pthread_create() call, which does not share any resources

    2. B

      Using the exec() call, which replaces the current process

    3. C

      Using the clone() call, which allows sharing of code, data, and files while creating a new stack

    4. D

      Using the fork() call, which duplicates the entire process

    Correct answer
    C

    Using the clone() call, which allows sharing of code, data, and files while creating a new stack

    Explanation

    Linux uses the clone() system call, which gives control over which resources to share (code, data, files) and creates a new stack.

  28. 28

    What does the clone() system call allow Linux threads to optionally share?

    1. A

      Memory space, file system information, and signal handlers

    2. B

      Only the program counter

    3. C

      Only file descriptors

    4. D

      Nothing; each thread has its own separate resources

    Correct answer
    A

    Memory space, file system information, and signal handlers

    Explanation

    The clone() call allows threads to share the file system, memory space, and signal handlers.

  29. 29

    Which thread library is used for Java applications?

    1. A

      Pthreads

    2. B

      Java threads (part of the Java language)

    3. C

      Windows threads

    4. D

      Linux threads

    Correct answer
    B

    Java threads (part of the Java language)

    Explanation

    Java has its own thread library built into the language.

Question 1 of 29
Question 1 of 29

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent