Ch.4 Operating System Concepts

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/104

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:51 PM on 6/10/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

105 Terms

1
New cards

[Compare]: Explain the fundamental difference in resource management and overhead between creating threads and creating processes.

Threads are more economical than processes because they share the resources of their parent process. Creating a process involves allocating separate memory space and resources, leading to higher overhead. Threads, being part of an existing process, reuse its resources, significantly reducing the cost of creation and context switching. This is analogous to having multiple workers within the same workshop (threads) versus setting up entirely new workshops for each worker (processes).

2
New cards

What is a potential drawback of the One-to-One threading model?

It typically incurs higher overhead due to more kernel threads.

3
New cards

Which standard defines POSIX Pthreads, a widely implemented API for thread management?

The POSIX standard.

4
New cards

What does the 'Balance' challenge in multicore programming entail?

Ensuring an even distribution of computational load across all parallel tasks.

5
New cards

In synchronous threading, what action does the parent thread take after creating child threads?

It pauses its execution and waits for all child threads to finish.

6
New cards

How are user threads primarily managed?

In user space by a thread library, without direct kernel involvement.

7
New cards

How does multithreading contribute to the responsiveness of interactive applications?

By allowing the application to perform tasks concurrently, preventing unresponsiveness during long operations.

8
New cards

What components are shared among threads within the same process?

Code section, data section, and operating system resources

9
New cards

What is the primary characteristic of the One-to-One threading model?

Each user thread is mapped to a unique kernel thread.

10
New cards

Why is 'Data Splitting' a challenge in multicore programming?

Programmers must effectively divide data into manageable chunks for concurrent processing by different threads.

11
New cards

The Many-to-Many threading model attempts to achieve which balance?

Balancing the efficiency of user-space thread management with the parallelism offered by kernel threads.

12
New cards

What is the main benefit of multithreading on multiprocessor systems?

It enables true parallel execution of different threads on separate processing cores, significantly increasing performance.

13
New cards

Why is creating and context-switching between threads more economical than for processes?

Threads share resources of their parent process, reducing overhead.

14
New cards

[Explain]: Describe the core distinction between asynchronous and synchronous threading, and provide a scenario where each would be the preferred strategy.

Asynchronous threading allows a parent thread to continue its execution immediately after creating a child thread, without waiting for the child to complete. This is ideal for tasks where responsiveness is key, such as in a graphical user interface (UI) where a background task shouldn't freeze the interface. Synchronous threading requires the parent thread to pause and wait for all child threads to finish before proceeding. This is useful when the parent needs to ensure all child threads have completed a task, especially if they are sharing and modifying data, like aggregating results from multiple calculations before the parent can proceed.

15
New cards

[Case Study]: A user is experiencing a word processor that becomes completely unresponsive for several seconds whenever it performs a background spell check on a long document. Explain how multithreading could be implemented to resolve this issue and maintain user interface responsiveness.

Multithreading can resolve the unresponsiveness by dedicating a separate thread to the long-running spell-checking task. The main thread would continue to handle user interface interactions (like typing or scrolling), while the background thread performs the spell check. This concurrent execution ensures that the UI thread is never blocked by the spell-checking operation, allowing the application to remain responsive to user input even during intensive background processing.

16
New cards

What is the core issue addressed by the 'Data Dependency' challenge in multicore programming?

Managing data access among parallel threads to prevent incorrect results or race conditions.

17
New cards

What is the primary challenge in debugging multithreaded programs compared to single-threaded ones?

The sheer number of potential execution paths and timing variations.

18
New cards

[Explain]: Describe the primary challenges a programmer faces when modifying existing single-threaded applications to effectively utilize multithreading on multicore systems, referencing at least three specific challenge areas.

Modifying single-threaded applications for multicore systems is challenging due to several factors. Key areas include: 1. Identifying Tasks: Analyzing the application to find independent sections suitable for parallel execution. 2. Balance: Ensuring computational load is evenly distributed across all parallel tasks to avoid idle cores. 3. Data Splitting: Effectively dividing data into chunks for concurrent access by different threads. 4. Data Dependency: Managing shared data access to prevent race conditions and ensure correct results. 5. Testing & Debugging: The non-deterministic nature of multithreaded execution makes errors difficult to reproduce and debug. Addressing these requires significant redesign and careful implementation.

19
New cards

[Case Study]: A software development team is building a cross-platform application intended to run on Linux, macOS, and Windows. They need to implement multithreading. Which primary thread library would be most suitable for ensuring portability across Linux and macOS, and which would be native to Windows?

For portability across Linux and macOS, POSIX Pthreads (Portable Operating System Interface for Unix) would be the most suitable choice. Pthreads are part of the POSIX standard and provide a standardized API for thread management on Unix-like systems. For Windows, the native and primary mechanism is Windows threads, which are implemented as a kernel-level library directly supported by the Windows operating system.

20
New cards

How does a parent thread typically wait for a child thread to finish in a Pthreads program?

By calling the pthread_join() function.

21
New cards

[Compare]: Contrast the One-to-One threading model with user threads managed solely in user space, highlighting their respective advantages and disadvantages.

The One-to-One model maps each user thread to a unique kernel thread. Its advantage is true parallelism, allowing multiple threads to run concurrently on different CPU cores. However, it incurs higher overhead due to the increased number of kernel threads. User threads, managed by a thread library in user space without direct kernel involvement, are more efficient for thread management and have lower overhead. Their limitation is that they cannot achieve true parallelism if the kernel only schedules one thread per process, and a blocking system call by one user thread can block all other user threads within the same process.

22
New cards

What is the primary advantage of a multithreaded process compared to a single-threaded application?

It can perform more than one task concurrently.

23
New cards

What fundamental components constitute a thread?

A thread ID, program counter, registers, and a stack

24
New cards

[Compare]: Contrast the Many-to-One threading model with the Many-to-Many threading model, highlighting their respective advantages and disadvantages, particularly concerning parallelism and blocking system calls.

The Many-to-One model maps multiple user-level threads to a single kernel thread. While thread management is efficient (done in user space), it has significant drawbacks: a blocking system call by one thread blocks the entire process, and true parallelism on multicore systems is impossible because only one thread can access the kernel at a time. The Many-to-Many model multiplexes many user-level threads onto a smaller or equal number of kernel threads. This model attempts to balance efficiency with parallelism. It avoids the issue of a single blocking system call halting the entire process (as other threads can still run on other kernel threads) and allows for parallelism across multiple cores, offering a more robust solution for modern systems.

25
New cards

[Compare]: Explain the fundamental difference between how concurrency is achieved on a single-core CPU versus a multicore CPU, and how this impacts the execution of multiple threads.

On a single-core CPU, concurrency is achieved through interleaved execution, where the processor rapidly switches between threads, creating the illusion of simultaneous execution. On a multicore CPU, concurrency allows for true parallel execution, where multiple threads can run simultaneously on different processor cores. This distinction is crucial because multicore systems can achieve genuine simultaneous execution, leading to significant performance gains, whereas single-core systems rely on rapid switching which can still introduce overhead.

26
New cards

What is a key characteristic of Windows threads?

They are implemented as a kernel-level library directly supported by the OS.

27
New cards

What is a primary benefit of asynchronous threading in server and UI applications?

It keeps the main program responsive while background tasks run.

28
New cards

In what scenario is synchronous threading often employed, and why?

When threads heavily share data, as the parent's wait ensures data finalization.

29
New cards

What is the purpose of the function pointer argument in the pthread_create() function?

It specifies the function where the new thread's execution will begin.

30
New cards

What is the primary function of a thread library?

To provide an API for thread creation and management.

31
New cards

What does the POSIX Pthreads specification primarily define?

An API for creating and synchronizing threads.

32
New cards

What is a significant drawback of the Many-to-One threading model?

It cannot leverage multiple CPU cores for true parallelism.

33
New cards

What is a key advantage of asynchronous threading?

The parent thread can continue executing without waiting for child threads.

34
New cards

What is the role of the function specified in a Pthreads program where separate threads begin execution?

It serves as the entry point for the thread's independent execution.

35
New cards

What makes testing and debugging multithreaded programs particularly difficult?

The non-deterministic nature of thread execution leads to unpredictable behavior.

36
New cards

On a single-core system, how is concurrency achieved in a multithreaded process?

Through the rapid interleaving of thread execution, creating the appearance of simultaneous activity.

37
New cards

What is a significant challenge for programmers when adapting existing applications for multithreading on multicore systems?

Effectively modifying sequential code to run in parallel introduces considerable complexity.

38
New cards

Under what condition is it necessary for a new process, created by fork(), to duplicate all threads from its parent process?

When the new process does not subsequently call exec().

39
New cards

Consider a scenario where a thread calls fork() and immediately after calls exec(). Which version of fork() is most appropriate in this situation, and why?

The version that duplicates only the calling thread, because exec() will replace the entire process anyway.

40
New cards

What is a key challenge when delivering signals in multithreaded UNIX programs?

Determining the correct thread to which the signal should be sent.

41
New cards

Which operating systems are supported by Intel Threading Building Blocks (TBB)?

Windows, Linux, and macOS

42
New cards

[Compare]: Contrast asynchronous and deferred thread cancellation, explaining the mechanism and implications of each.

Thread cancellation terminates a thread before its completion. Asynchronous cancellation allows one thread to immediately terminate a target thread. Deferred cancellation, however, requires the target thread to periodically check if it should terminate, allowing for an orderly shutdown. Deferred cancellation is generally preferred as it gives the thread a chance to clean up resources properly.

43
New cards

What is the behavior of the exec() system call in a multithreaded program?

It replaces the entire process, including all threads, with a new program.

44
New cards

In UNIX systems, what is the primary function of a signal?

To notify a process about a specific event.

45
New cards

What is the primary environment in which OpenMP facilitates parallel programming?

Shared-memory architectures

46
New cards

In thread cancellation, what distinguishes deferred cancellation from asynchronous cancellation?

Deferred cancellation allows the target thread to decide when to terminate, while asynchronous cancellation is immediate.

47
New cards

What is the fundamental difference between OpenMP's approach and that of Intel TBB regarding compiler integration?

OpenMP requires compiler directives, while TBB is a standalone library.

48
New cards

What is the fundamental principle behind the operation of a thread pool?

Pre-creating threads that wait for tasks to avoid per-request creation overhead.

49
New cards

How does the behavior of fork() and exec() system calls differ in multithreaded programs compared to single-threaded programs?

Their semantics are altered, affecting how threads are handled during process duplication and replacement.

50
New cards

In the context of Grand Central Dispatch (GCD), what is the role of the 'main queue'?

It is the primary serial queue associated with each process.

51
New cards

[Compare]: Differentiate between serial and concurrent dispatch queues in Grand Central Dispatch (GCD), focusing on how tasks are processed.

Both serial and concurrent dispatch queues process tasks in FIFO order. However, a serial queue executes only one task at a time; a task must complete before the next one begins. A concurrent queue, on the other hand, can remove and execute multiple tasks simultaneously, allowing for parallel processing. Each process has a main serial queue, and developers can create additional serial or concurrent queues.

52
New cards

What is the primary responsibility shifted from application programmers to compilers and run-time libraries in implicit threading?

Identifying parallelizable tasks within applications.

53
New cards

How are compiler directives used in OpenMP to enable parallel execution?

Directives are embedded in the source code to instruct the OpenMP runtime library to execute enclosed code in parallel.

54
New cards

How do tasks behave when placed on a serial dispatch queue?

Tasks are executed one after another, with each task completing before the next begins.

55
New cards

What is required to access the OpenMP Application Programming Interface (API) in C/C++ programs?

Including the 'omp.h' header file

56
New cards

What distinguishes a concurrent dispatch queue from a serial dispatch queue in terms of task execution?

Concurrent queues allow multiple tasks to execute in parallel, while serial queues execute tasks one at a time.

57
New cards

What is the primary characteristic of deferred thread cancellation?

The target thread periodically checks if it should terminate itself in an orderly manner.

58
New cards

What is the primary function of a dispatch queue in Grand Central Dispatch (GCD)?

To hold tasks and assign them to available threads from a managed pool.

59
New cards

[Compare]: Explain the fundamental difference between implicit threading and explicit threading in terms of who is responsible for thread creation and management.

Implicit threading shifts the responsibility for creating and managing threads from application programmers to compilers and run-time libraries. Programmers identify parallelizable tasks (functions), and the runtime library assigns them to threads, often using a many-to-many model. Explicit threading, in contrast, requires the programmer to manually create, manage, and synchronize threads using APIs like pthreads or Windows threads.

60
New cards

What is a significant challenge associated with asynchronous thread cancellation?

Potential for resource leaks or corrupted shared data.

61
New cards

What are the two main advantages offered by using a thread pool in a multithreaded server?

Faster request servicing via existing threads and a bounded number of active threads.

62
New cards

Compare asynchronous and deferred thread cancellation, highlighting their fundamental differences in termination mechanisms and safety implications.

Asynchronous cancellation involves one thread immediately and abruptly terminating a target thread. This is generally considered unsafe because the target thread has no control over when it is terminated and may not have a chance to clean up resources or complete critical operations, potentially leading to resource leaks or data corruption. Deferred cancellation allows the target thread to periodically check if it should terminate. This cooperative approach enables the thread to perform necessary cleanup operations in an orderly fashion before exiting, making it a safer method for thread termination. The key difference lies in the control and predictability of the termination process: asynchronous is immediate and externally forced, while deferred is controlled and internally managed by the target thread.

63
New cards

What happens to all existing threads in a process when the exec() system call is invoked in a multithreaded program?

The entire process, including all its threads, is replaced by the new program.

64
New cards

[Explain]: Describe the core problem that thread pools solve for multithreaded servers and how they address it.

Multithreaded servers that create a new thread for each request face two main issues: the overhead of constantly creating and destroying threads, and the potential for an unbounded number of threads, which can degrade system performance. Thread pools solve this by pre-creating a fixed number of threads at startup. These threads wait in a pool and are assigned tasks as requests arrive, avoiding the creation/destruction overhead and bounding the number of active threads.

65
New cards

What is a significant drawback of creating a new thread for every incoming request in a multithreaded server?

It can lead to an unbounded number of threads running concurrently.

66
New cards

[Compare]: Explain the fundamental differences between synchronous and asynchronous signals in UNIX systems, providing an example for each and describing how each type of signal is typically delivered within a multithreaded process.

Synchronous signals are generated by events occurring within the same process that receives the signal, such as illegal memory accesses or division by zero operations. They are delivered to the specific thread that caused the signal. Asynchronous signals are generated by events external to a running process, typically sent from another process. Some asynchronous signals, like process termination signals, may need to be delivered to all threads within the process, while others might be delivered to a subset or a dedicated thread.

67
New cards

According to OpenMP principles, what is the purpose of compiler directives within parallel regions?

To instruct the OpenMP runtime library to execute the enclosed code block in parallel.

68
New cards

What are the two primary methods for terminating a thread before its natural completion?

Asynchronous cancellation and deferred cancellation

69
New cards

How does the Intel TBB task scheduler contribute to efficient parallel execution?

By providing load balancing and being cache-aware to prioritize tasks.

70
New cards

What is the typical sequence of events when a signal is handled in UNIX?

Generation, delivery, handling.

71
New cards

How does OpenMP enable developers to specify code segments for parallel execution?

By embedding compiler directives within designated parallel regions

72
New cards

Which technology is developed by Apple for macOS and iOS to enable parallel task execution?

Grand Central Dispatch (GCD)

73
New cards

[Explain]: How does Intel Threading Building Blocks (TBB) simplify parallel programming for C++ developers, and what are the key features of its task scheduler?

Intel TBB simplifies parallel programming by providing a C++ template library, meaning it doesn't require proprietary compilers or language extensions, ensuring broad compatibility. Developers specify tasks that can run in parallel, and TBB's task scheduler handles the complexities of thread management. The scheduler is designed for performance, offering load balancing to distribute work evenly across threads and cache awareness to prioritize tasks likely to benefit from data already in the CPU cache.

74
New cards

When a task is submitted to a thread pool and no threads are immediately available, what is the typical next step?

The task is queued until a thread becomes free.

75
New cards

What is a key characteristic of Intel Threading Building Blocks (TBB) that enhances its compatibility?

It functions as a library, not requiring special compiler support.

76
New cards

[Case Study]: A multithreaded C++ application uses OpenMP for parallel processing. The application encounters a division by zero error in one of its worker threads. Subsequently, a user presses Ctrl+C to interrupt the program. Describe the nature of these two events (division by zero and Ctrl+C) as signals, and explain how each signal should ideally be delivered within the multithreaded context.

The division by zero error is a synchronous signal. It is generated by an event occurring within the specific thread that performed the erroneous operation. Therefore, it should be delivered only to that thread. The Ctrl+C interrupt is typically an asynchronous signal, generated externally to the running process. Depending on the application's design and the specific signal handling, it might be delivered to all threads in the process to ensure a controlled termination, or to a designated signal-handling thread.

77
New cards

In the context of Intel Threading Building Blocks (TBB), what is the developer's primary role regarding parallelism?

To specify which tasks within the application are suitable for parallel execution.

78
New cards

What is the direct consequence when a kernel thread encounters a blocking operation?

Its associated Lightweight Process (LWP) and mapped user thread also block.

79
New cards

[Compare]: Explain the fundamental difference in how Linux's `fork()` and `clone()` system calls create new tasks, focusing on resource duplication versus selective sharing.

The `fork()` system call creates a new task by duplicating all of the parent process's associated data structures, resulting in a completely independent new task. In contrast, the `clone()` system call creates a new task that shares data structures with the parent. The specific data structures shared are determined by flags passed to `clone()`, allowing for flexible resource management and potentially reduced overhead compared to `fork()`.

80
New cards

How does thread-local storage (TLS) differ from static data in Pthreads?

TLS data is unique to each thread, whereas static data is shared by all threads.

81
New cards

How does the kernel signal that a previously blocked thread is now eligible to run?

By making another upcall to the thread library, potentially allocating a new LWP.

82
New cards

What is the effect of using the `CLONE_VM` flag with the `clone()` system call in Linux?

Parent and child tasks share the same virtual memory space.

83
New cards

What is the central kernel data structure in Linux that holds information about each running task?

struct task_struct

84
New cards

What is the effect of calling `pthread_testcancel()` within a Pthreads thread?

It terminates the thread if a cancellation request is pending, otherwise it returns.

85
New cards

[Compare]: Explain the key differences between thread-local storage (TLS) and global/static data in terms of scope, persistence, and sharing among threads.

Thread-local storage (TLS) provides each thread with its own independent copy of data, which persists across function calls within that thread. This is distinct from global or static data, which is shared among all threads in a process. While local variables are only accessible within a single function invocation, TLS data is accessible throughout the thread's lifetime. This isolation is crucial for maintaining thread-specific states or configurations without interference from other threads.

86
New cards

[Case Study]: A long-running scientific simulation is running in a thread. The simulation involves complex calculations and periodically writes its progress to a file. The user wants to be able to stop the simulation if it takes too long, but also wants to ensure that the simulation doesn't get interrupted mid-write to the file. Where should `pthread_testcancel()` be called to achieve this?

The `pthread_testcancel()` function should be called immediately before and after the file write operation. This ensures that the thread checks for cancellation requests only when it is not in the middle of a critical file operation. If a cancellation request is pending when `pthread_testcancel()` is called, the thread will terminate. If no request is pending, the thread continues its execution. This strategy leverages deferred cancellation, allowing the thread to safely complete its file write before potentially being terminated.

87
New cards

If the `clone()` system call is invoked in Linux without any flags, what is its behavior equivalent to?

The traditional fork() system call

88
New cards

[Process]: Describe the sequence of events that occur when a kernel thread blocks, focusing on the roles of Lightweight Processes (LWPs) and upcalls in the scheduler activation model.

When a kernel thread blocks, the kernel initiates an upcall to the application's thread library, signaling the impending block and identifying the thread. The kernel then allocates a new LWP to the application. The thread library's upcall handler executes on this new LWP, saves the state of the blocking thread, and relinquishes the current LWP. It then schedules another eligible thread onto the new LWP. This mechanism ensures that the application can continue to make progress even when some threads are blocked, by utilizing the newly allocated LWP.

89
New cards

Which flag, when used with Linux's `clone()` system call, ensures that the current working directory and root directory are shared between parent and child tasks?

CLONE_FS

90
New cards

How does the `fork()` system call in Linux differ from `clone()` in terms of resource duplication?

fork() duplicates all associated data structures, while clone() points to shared structures based on flags.

91
New cards

In many-to-many and two-level threading models, what is the role of a Lightweight Process (LWP)?

An intermediary virtual processor scheduled by the OS to run kernel threads.

92
New cards

How does the operating system manage the execution of threads in many-to-many or two-level models?

By scheduling kernel threads, which are run on virtual processors called LWPs.

93
New cards

In Pthreads, what is the primary characteristic of deferred cancellation?

Threads can only be cancelled at specific, user-defined points in their execution.

94
New cards

[Explain]: Explain the purpose and mechanism of Pthreads cleanup handlers, emphasizing their role in resource management during thread cancellation.

Pthreads cleanup handlers are functions registered with the thread that are automatically invoked when a thread is cancelled. Their primary purpose is to ensure proper resource management by releasing any resources (e.g., memory, file locks, open files) that the thread may have acquired before its termination. This prevents resource leaks and maintains system stability by guaranteeing that acquired resources are deallocated or released, even in the event of unexpected thread cancellation.

95
New cards

In Linux, when a new task is created using `clone()`, how does it typically relate to the parent task's data structures?

It points to the parent task's data structures, with sharing determined by flags.

96
New cards

In threading, what is the primary purpose of the `pthread_key_t` datatype?

To create a unique identifier for accessing thread-specific data.

97
New cards

What system call in Linux allows for the creation of new tasks with configurable resource sharing between parent and child?

clone()

98
New cards

What does the `__thread` keyword in GCC provide to developers?

A simplified way to declare variables with thread-local storage.

99
New cards

In Linux, what is the unified term used to refer to both processes and threads?

Task

100
New cards

What is the function of 'scheduler activation' in threading models?

A communication scheme where the kernel provides LWPs for the application to schedule user threads onto.