Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 52 pages
Exam (elaborations)

CSE 445 MIDTERM 2 EXAM 2026 COMPLETE (167) CURRENT TESTING QUESTIONS AND CORRECT ANSWERS WITH DETAILED RATIONALES.

Document preview thumbnail
Preview 4 out of 52 pages

Prepare for the CSE 445 Midterm 2 Exam with practice questions covering core computer science concepts, software development principles, system design, programming methodologies, data processing, and problem-solving techniques. This study guide helps reinforce essential course material and supports effective exam preparation. Designed to improve analytical thinking skills and boost confidence in applying computer science concepts to technical challenges. Suitable for computer science, software engineering, and information technology students

Content preview

Page 1 of 52


CSE 445 MIDTERM 2 EXAM 2026 COMPLETE (167)
CURRENT TESTING QUESTIONS AND CORRECT
ANSWERS WITH DETAILED RATIONALES.
CSE
Prepare for the CSE 445 Midterm 2 Exam with practice questions covering core
computer science concepts, software development principles, system design,
programming methodologies, data processing, and problem-solving techniques. This
study guide helps reinforce essential course material and supports effective exam
preparation. Designed to improve analytical thinking skills and boost confidence in
applying computer science concepts to technical challenges. Suitable for computer
science, software engineering, and information technology students.


MULTIPLE CHOICE.
Section 1: Threads and Concurrency (Questions 1-18)

1 Consider the following C++ code snippet using std::atomic<int> x(0), y(0). Thread 1: x.store(1,
std::memory_order_release); y.store(1, std::memory_order_relaxed); Thread 2: while
(y.load(std::memory_order_relaxed) != 1); int r1 = x.load(std::memory_order_acquire); Is it possible for r1 to be
0 after both threads complete? Assume x and y are initially 0.

A) No, because the release-acquire on x ensures that the store to x is visible to the load in Thread 2.
B) Yes, because the store to y uses relaxed ordering and the load of y is relaxed, so the while loop may complete
before the store to x is visible.
C) Yes, because there is no synchronizes-with relationship between the store to x and the load of x.
D) No, because the store to y with relaxed ordering still provides a happens-before guarantee for the store to x.
Answer: B
Rationale: The store to y is relaxed, and the load of y is relaxed, so the while loop can observe y==1 before the store
to x (which uses release) becomes visible to the acquire load of x. Even though the store to x is release, it only
synchronizes with an acquire load of the same variable. Since Thread 2 does not acquire -load x until after the
relaxed load of y, it is possible that the release store to x has not yet propagated, and r1 may read 0.

2 A concurrent hash table uses separate chaining with per-bucket mutexes. Each bucket has its own lock. A writer
thread that inserts a key-value pair locks the bucket corresponding to the hash of the key. Under high
contention, the system shows poor scalability. Which of the following is the most likely cause?
A) False sharing due to bucket locks being on the same cache line.
B) Lock contention on the global memory allocator used for new nodes.
C) Deadlock caused by two threads trying to lock the same bucket.
D) Priority inversion due to low-priority threads holding locks.
Answer: B
Rationale: Even with per-bucket locking, if every insertion allocates memory (e.g., new node) using a global
allocator (like malloc), that allocator itself may be a bottleneck under high concurrency. False sharing (A) could
cause cache coherence traffic but is less likely to be the primary scalability issue. Deadlock (C) is not caused by
locking the same bucket; that would be contention, not deadlock. Priority inversion (D) is a real-time issue, not
generally a scalability issue.

3 Which of the following statements about the ABA problem in lock -free data structures is correct?

, Page 2 of 52

A) The ABA problem occurs only when using compare-and-swap (CAS) on pointer-based structures, and can be
solved by using double-wide CAS or tagged pointers.
B) The ABA problem is a form of deadlock that occurs when threads A and B both try to acquire the same lock.
C) The ABA problem can be ignored if the data structure uses only atomic loads and stores without CAS.
D) The ABA problem arises when a thread reads a value, is preempted, and another thread changes the value and
then changes it back, causing the first thread's CAS to succeed incorrectly.

Answer: D
Rationale: The ABA problem is exactly as described in D: a thread reads value A, another thread changes it to B and
then back to A, so the first thread's CAS sees A and succeeds, but the structure's state has changed. Option A is
partially correct but not universally; ABA can occur in non-pointer contexts as well. Option B is wrong; it is not a

, Page 3 of 52

deadlock. Option C is wrong; ABA is only relevant when using CAS or similar RMW operations.

4 A multithreaded program uses a single global lock to protect all shared data. Under which workload is this
coarse-grained locking most likely to perform acceptably?
A) A workload with many short critical sections and a high number of threads.
B) A workload where each thread spends most of its time in the critical section.
C) A workload where the critical section is very short and the number of threads is small.
D) A workload where threads frequently block on I/O outside the critical section.
Answer: C
Rationale: Coarse-grained locking performs best when contention is low, i.e., few threads and short critical sections.
With many threads (A) or long critical sections (B), contention increases, causing threads to spin or block. If
threads block on I/O (D), they hold the lock while blocked, causing even worse contention.

5 A concurrent queue implementation uses two locks: one for the head and one for the tail. Enqueue operations
lock the tail lock, and dequeue operations lock the head lock. Under what condition can this queue suffer from
deadlock?
A) When the queue becomes empty and a dequeue tries to acquire the tail lock.
B) When an enqueue and a dequeue are called concurrently on a non -empty queue.
C) When an enqueue tries to acquire the head lock and a dequeue tries to acquire the tail lock.
D) When the queue has only one element and both enqueue and dequeue attempt to acquire both locks.
Answer: D
Rationale: If the queue has one element, the head and tail point to the same node. An enqueue may need to update
the tail's next pointer (requires tail lock) and also potentially update the head if the queue was empty, but in this
case, a dequeue may need to update both head and tail when removing the last element. If both threads try to
acquire both locks but in different orders, deadlock can occur. Options A, B, and C do not involve holding two
locks simultaneously in a cycle.

6 In the context of memory consistency models, which of the following best describes the difference between
sequential consistency (SC) and total store order (TSO)?
A) SC requires that all memory operations appear to execute in some total order consistent with program order,
while TSO allows store operations to be buffered and appear out of order relative to loads.
B) SC and TSO are identical; TSO is just another name for SC.
C) TSO is weaker than SC because it allows both loads and stores to be reordered.
D) SC allows store-load reordering, while TSO does not.
Answer: A
Rationale: Sequential consistency (SC) ensures that the result of any execution is the same as if the operations of all
processors were executed in some sequential order consistent with each processor's program order. TSO, used in
x86, allows stores to be buffered (store buffer), so a later load can bypass an earlier store, causing store -load
reordering. Option C is incorrect because TSO only allows store-load reordering, not load-load or load-store.
Option D is backwards.

7 A barrier synchronization is implemented using a sense-reversing barrier. Each thread arrives at the barrier and
spins on a local flag. Which of the following is a key advantage of this design over a simple centralized counter
with a spinlock?
A) It avoids the need for atomic operations entirely.
B) It reduces cache coherence traffic because each thread spins on its own cache line.
C) It guarantees fairness among threads.

, Page 4 of 52

D) It allows threads to exit the barrier immediately upon arrival without waiting.
Answer: B
Rationale: In a sense-reversing barrier, each thread spins on a private flag (or a flag in its own cache line), reducing
invalidation traffic compared to a centralized counter where all threads spin on the same variable. Option A is false;
atomic operations are still needed to update the count. Option C is not a guaranteed property; fairness depends on
implementation. Option D is false; threads must wait until all arrive.

8 Consider a readers-writers lock that gives priority to readers (i.e., if a reader holds the lock, other readers can
acquire it, but writers must wait until all readers release). Which of the following is a potential problem under
high contention?
A) Starvation of readers because writers may continuously acquire the lock.
B) Starvation of writers because new readers can keep arriving and prevent writers from ever acquiring the lock.
C) Deadlock because readers and writers may hold locks in different orders.
D) Priority inversion because a low-priority writer may block a high-priority reader.
Answer: B
Rationale: With reader-priority, if readers arrive continuously, writers can be starved indefinitely. Option A
describes writer-priority. Option C is not specific to this lock. Option D is a real-time issue, not inherent to the
lock's priority policy.

9 Which of the following statements about lock-free data structures is false?
A) Lock-free data structures guarantee that at least one thread makes progress in a finite number of steps.
B) Wait-free data structures guarantee that every thread makes progress in a finite number of steps.
C) Lock-free data structures cannot suffer from deadlock or livelock.
D) Lock-free data structures are always faster than lock-based ones under low contention.
Answer: D
Rationale: Lock-free data structures can have overhead from CAS retries and memory reclamation, and under low
contention, a simple lock-based approach may be faster due to lower overhead. Options A and B are correct
definitions. Option C is true: lock-free implies freedom from deadlock and livelock, though livelock is possible if
not carefully designed, but the statement is generally considered true.

10 A program uses pthreads and a mutex to protect a shared variable. The program runs on a multi-core system.
The critical section is very short (a few instructions). Which of the following optimizations is most likely to
improve performance?
A) Replace the mutex with a spinlock.
B) Increase the number of threads.
C) Use a reader-writer lock instead of a mutex.
D) Add memory barriers before and after the critical section.
Answer: A
Rationale: For very short critical sections, the overhead of blocking (context switching) in a mutex may dominate. A
spinlock busy-waits, which can be more efficient if the wait time is short. Increasing threads (B) would likely
increase contention. A reader-writer lock (C) adds overhead and is beneficial only when read operations dominate.
Memory barriers (D) are already implicit in mutex operations and adding them would not help.

11 In a multithreaded C program using Pthreads, a developer implements a shared counter protected by a mutex.
The counter is incremented 1000 times by each of 10 threads. Despite proper mutex locking, the final counter
value is sometimes less than 10000. Which of the following is the most likely cause?
A) The mutex is not initialized as recursive, causing deadlock.

Document information

Uploaded on
September 2, 2026
Number of pages
52
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$23.98

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Tutorelias
4.5
(2)
Sold
19
Followers
0
Items
3274
Last sold
1 week ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions