L9 Networks & Operating Systems Flashcards

1
Q

What is a thread in the context of process management?

A

• A thread is the basic unit of CPU utilization.
• It includes a thread ID, program counter, register set, and stack.
• Threads share code, data, and OS resources with other threads of the same process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the main benefit of using threads in applications?

A

• Threads enable simultaneous execution of tasks, improving responsiveness and CPU utilization.
• They are lightweight and more economical than creating new processes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the differences between concurrency and parallelism?

A

• Concurrency: Tasks appear to run in parallel through time-slicing; not necessarily at the same time.
• Parallelism: Tasks actually run at the same time on multiple processors or cores.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does sequential execution differ from concurrent and parallel execution?

A

• Sequential: One task executes at a time, others must wait.
• Concurrent: Multiple tasks are interleaved in execution.
• Parallel: Multiple tasks execute simultaneously on separate CPUs/cores.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the lifecycle of a Java thread?

A

• NEW → RUNNABLE → RUNNING → may go to WAITING, TIMED_WAITING, BLOCKED, or TERMINATED.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens when a thread enters the WAITING state?

A

• It waits indefinitely for another thread to perform an action (e.g., wait() called).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Amdahl’s Law and how does it relate to multicore performance?

A

• Amdahl’s Law estimates the potential speedup of a program using multiple cores.
• Formula:
speedup ≤ 1 / (S + (1 - S)/N)
where S = serial fraction, N = number of cores.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the advantages of multithreaded server architecture?

A

• Efficient handling of multiple client requests using threads instead of processes.
• Lower overhead and quicker context switching.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can threads be created in Java?

A

• By extending the Thread class and overriding run()
• By implementing the Runnable interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is multithreading beneficial in multicore systems?

A

• It allows actual parallel execution of threads, improving performance and scalability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the RUNNABLE state mean in Java thread lifecycle?

A

• The thread is ready to run and waiting for CPU time from the thread scheduler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the key benefits of threads over processes?

A

• Faster creation and context switching
• Shared memory space
• Improved responsiveness
• Better scalability on multicore systems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does Java put a thread into TIMED_WAITING state?

A

• Using methods like sleep(millis) or wait(millis)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between BLOCKED and WAITING states in Java?

A

• BLOCKED: Waiting for a lock
• WAITING: Waiting indefinitely for an event or action

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are common use cases for threads in desktop applications?

A

• UI responsiveness (e.g., UI thread + background threads)
• Networking (e.g., downloading while rendering UI)
• Parallel computations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What methods are commonly used to control thread behavior in Java?

A

• start(), run(), sleep(), wait(), notify(), interrupt()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What happens when a thread finishes execution?

A

• It transitions to the TERMINATED state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Why is thread creation more efficient than process creation?

A

• Thread creation uses shared memory and resources of the process, avoiding expensive memory allocation and setup steps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

In what scenario would concurrency not result in performance gain?

A

• On single-core systems where tasks are context-switched rather than executed in parallel; overhead may even reduce performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Why is synchronization important in concurrent and parallel systems?

A

• To prevent race conditions, ensure data integrity, and avoid deadlocks when multiple threads access shared data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are some risks or drawbacks of using multithreading?

A

• Deadlocks, race conditions, difficult debugging, increased complexity, and nondeterministic behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Compare RUNNABLE vs. RUNNING in Java threads.

A

• RUNNABLE: Eligible to run but waiting for CPU.
• RUNNING: Currently executing on a CPU.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Describe an application that benefits from both concurrency and parallelism.

A

• A video game: concurrent threads for input, rendering, and audio; parallel execution on multicore systems improves performance.

24
Q

How does multithreading improve responsiveness in GUI applications?

A

• Background threads handle long-running tasks (e.g., file download), allowing the UI thread to stay interactive.

25
When would you prefer implementing Runnable over extending Thread?
• When you need to inherit from another class (Java doesn’t support multiple inheritance), or want to decouple task logic from threading.
26
What happens if you call run() directly instead of start() on a thread?
• It will execute like a normal method call in the current thread, not in a separate thread.
27
How does Java handle thread scheduling?
• It’s managed by the JVM and OS; generally based on thread priority and time-slicing.
28
What type of execution is illustrated in Diagram1.png?
* Parallel execution, where Task 1 and Task 2 run simultaneously on two separate CPUs.
29
According to Diagram1.png, what happens to Task 3 and Task 4 at time t1?
* They are in a waiting state while Tasks 1 and 2 are running.
30
At time t2 in Diagram1.png, which tasks begin execution?
* Task 3 and Task 4 start running after Task 1 and Task 2 terminate.
31
What does the process state table in Diagram1.png describe?
* It shows the status (running/waiting/terminated) of each task at time t1 and t2.
32
What type of execution is shown in Diagram2.png?
* Parallel concurrent execution, where tasks are split and interleaved across CPUs.
33
How are the tasks scheduled in Diagram2.png?
* Tasks 1 and 2 are alternated on CPU 1, while Tasks 3 and 4 are alternated on CPU 2.
34
How many CPUs are used in Diagram2.png and what is their role?
* Two CPUs handle interleaved chunks of four tasks concurrently.
35
What execution model does Diagram3.png illustrate?
* Sequential execution, using a single CPU to run tasks one at a time.
36
According to Diagram3.png, what is the state of Task 2 during t1?
* Task 2 is in a waiting state while Task 1 is running.
37
In Diagram4.png, which task is likely to finish first? Why?
* Task 1 or 2, depending on allocation of slices and task size, since they are scheduled earlier and more frequently.
38
What does Diagram5.png demonstrate about parallelism?
* A single task (Task 1) is split into subtasks that execute in parallel on multiple CPUs.
39
Why is parallelism effective as shown in Diagram5.png?
* It reduces overall execution time by distributing work across processors.
40
Which column in Diagram6.png describes execution on a single-core CPU?
* Concurrency — because multiple tasks are interleaved over time, not running simultaneously.
41
What does Diagram7.png represent?
* A single-threaded process, containing one thread of control sharing all process resources.
42
What does Diagram8.png illustrate?
* A multithreaded process, where multiple threads share the same code and data but have individual stacks and registers.
43
What’s the significance of separate stacks for each thread in Diagram8.png?
* Prevents one thread’s local variables and function calls from interfering with another’s execution flow.
44
What comparison is made in Diagram9.png?
* It compares single-threaded vs. multithreaded processes side-by-side, highlighting resource sharing and execution differences.
45
How does memory sharing differ between the two processes in Diagram9.png?
* Single-threaded: No need for synchronization. * Multithreaded: Requires synchronization for shared code and data.
46
What does Diagram10.png show about thread creation in Java?
* Threads can be created by implementing the Runnable interface, then defining run().
47
What must be done after implementing Runnable to actually start the thread?
• Pass the Runnable to a Thread object and call start() on it.
48
What architecture is illustrated in Diagram11.png?
* A multithreaded server model: server creates a new thread to handle each client request.
49
How does the server maintain responsiveness in Diagram11.png?
* It immediately returns to listening for requests after spawning a thread to handle the current one.
50
What is the formula shown in Diagram12.png and what does it describe?
* Amdahl’s Law: speedup ≤ 1 / (S + (1 - S)/N) * It describes theoretical performance gain from parallel processing.
51
How is a thread created using extends Thread as shown in Diagram13.png?
* By subclassing the Thread class and overriding run() to define the task.
52
What is shown in Diagram14.png about thread lifecycle?
* Transitions between Java thread states: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED.
53
Why might a thread transition from RUNNABLE to BLOCKED in Diagram14.png?
* It attempts to access a locked resource (e.g., enters a synchronized block while another thread holds the lock).
54
What does Diagram15.png depict in Java threading?
* Full code example of thread creation by extending Thread, and starting it using start().
55
In Diagram15.png, what does start() do that run() does not?
* start() creates a new thread and invokes run() asynchronously; calling run() directly runs it on the current thread.
56
What is the function of the operating system in Diagram16.png?
* Dispatches threads from READY to RUNNING state and returns them when their time slice expires.
57
What state transitions are emphasized in Diagram17.png?
* The diagram highlights movement between all Java thread states, triggered by events like wait(), notify(), I/O, or task completion.