Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 4 fuera de 52 páginas
Examen

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

Document preview thumbnail
Vista previa 4 fuera de 52 páginas

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

Vista previa del contenido

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.

Información del documento

Subido en
2 de septiembre de 2026
Número de páginas
52
Escrito en
2026/2027
Tipo
Examen
Contiene
Preguntas y respuestas
$23.98

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Tutorelias
4.5
(2)
Vendido
19
Seguidores
0
Artículos
3239
Última venta
1 semana hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes