πŸŽ“ BookMCQ
← Back to 5. Process Synchronization

πŸ“ Transactional Memory Alternative Approache in Process Synchronization (36 MCQs)

Atomic Transactions as an Alternative to Explicit Locking

Transactional memory is a synchronization approach in which a group of memory operations executes as an atomic transaction. Instead of explicitly acquiring and releasing locks around every shared-data operation, a thread begins a transaction, performs memory updates, and attempts to commit them. The system checks for conflicting concurrent accesses and either accepts the transaction or aborts and retries it.

Why Fine-Grained Lock Management Becomes Difficult

Programs using multiple locks must carefully manage acquisition order, release operations, and shared-resource dependencies. Incorrect combinations can cause deadlocks, while excessive locking limits parallelism. Transactional memory offers an alternative by allowing operations to proceed optimistically and detecting conflicts, reducing the need for programmers to coordinate every protected memory access manually.

Transaction Begin, Conflict Detection, Commit, and Abort

A thread starts a transaction and reads or modifies shared memory within the transactional region. The implementation tracks relevant memory accesses and checks whether another transaction has created a conflicting update. If no conflict occurs, changes commit atomically. If a conflict or unsupported operation occurs, the transaction aborts and its updates are discarded before possible retry.

Two Transactions Updating the Same Account Balance

Suppose transactions T1 and T2 both read a bank balance of 1,000 and each attempts to withdraw 100. If both execute concurrently, conflict detection identifies their overlapping updates. One transaction may commit while the other aborts and retries. On retry, the second reads the updated balance of 900 and commits a final value of 800.

Concurrency Benefits and Transaction Retry Limitations

Transactional memory can simplify synchronization in workloads with relatively low memory conflicts and independent transactions. Hardware transactional memory may execute suitable operations efficiently, while software implementations track conflicts through runtime mechanisms. However, repeated conflicts cause aborts, retries can lead to starvation, and some operations cannot safely occur inside transactions. Hardware support and memory-model limitations also vary.

Misconceptions About Transactional Memory

'Transactional memory eliminates every possible deadlock' is incorrect because surrounding locks and retries may still create progress problems. 'Every transaction commits successfully on its first attempt' is incorrect because conflicts can cause aborts. 'Transactional memory always executes transactions in hardware' is incorrect because software implementations also exist.

Exam Focus: Transaction Commit and Conflict Tracing

Trace transactional reads, writes, conflict detection, commit, and abort operations. Determine how overlapping updates affect the final shared value and explain why a failed transaction must be retried. Questions may compare transactional memory with mutex-based locking, distinguish hardware from software implementations, and examine conflicts, retries, and atomicity.

Key Terms of Transactional Memory

  • Transaction - Group of operations treated atomically.
  • Commit - Makes transactional changes permanent.
  • Abort - Discards uncommitted transactional changes.
  • Conflict detection - Identifies incompatible memory accesses.
  • Retry - Re-executes an aborted transaction.
  • Hardware transactional memory - Processor-supported transaction execution.
12
Easy
12
Medium
12
Hard

πŸ“ All Transactional Memory Alternative Approache in Process Synchronization MCQs

Q1. A transaction updates a bank balance and a transfer record. Which guarantee requires both memory updates to become committed together or neither to become visible?

A.Serial scheduling
B.Cache coherence
C.Priority inheritance
D.Atomicity βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: Atomicity treats the transaction as one indivisible operation. If execution fails before commit, its supported memory changes are discarded; if it commits, the complete set of changes becomes effective together.

Q2. A monitoring thread reads a shared inventory structure while another transaction is halfway through changing two related fields. Which guarantee prevents the reader from observing the transaction’s partial updates?

A.Validation
B.Retry fairness
C.Speculation
D.Isolation βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: Isolation prevents other transactions from observing intermediate transactional changes. The reader should see a state consistent with a completed transaction, rather than a mixture containing some old values and some uncommitted new values.

Q3. Several transactions execute concurrently, but the final result must be equivalent to some valid one-at-a-time ordering. Which correctness property describes this requirement?

A.Mutual exclusion
B.Starvation freedom
C.Busy waiting
D.Serializability βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: Serializability requires the concurrent outcome to match an equivalent serial ordering of transactions. It permits overlap during execution while preserving the logical effect of a valid one-at-a-time sequence for the relevant shared state. for the relevant transactions.

Q4. A web service runs two transactions: one updates customer record 12, while the other updates an unrelated record 91. What advantage can transactional memory offer over one global mutex?

A.It must merge both records into one memory location
B.It guarantees that neither transaction performs validation
C.It forces the transactions to execute in arrival order
D.It can allow both nonconflicting transactions to progress concurrently βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: Because the transactions access disjoint data, they need not conflict. Transactional memory may therefore allow overlap, whereas one global mutex would serialize the entire protected region regardless of which records are touched.

Q5. A student says a transaction can commit x=65x = 65 first and change y to 35 later because the final sum will equal 100100. What is the flaw?

A.The transaction must update only y
B.A transaction cannot update two fields
C.The final values cannot add to 100
D.An observer could see x = 65 with y = 60, violating the invariant before the second change βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: The flawed step is exposing the first update before the second. Because the invariant covers both fields, the transaction must publish the complete pair together so observers cannot see an invalid intermediate state.

Q6. Two concurrent transactions access the same memory location. Under the usual conflict rule for transactional memory, when is their access a conflict?

A.Only when both transactions read the location
B.Only when both transactions write different values
C.Only when the location is a pointer
D.When at least one access writes the location βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: Concurrent reads of the same location can coexist because neither changes the value. A write can invalidate another transaction’s observation or compete with another write, so any shared access pair containing a write conflicts.

Q7. Transaction T1 has read set R1={a,b}R_1 = \{a,b\} and write set W1={c}W_1 = \{c\}. Transaction T2 has read set R2={c,d}R_2 = \{c,d\} and write set W2={e}W_2 = \{e\}. What is the relevant relationship?

A.Their sets are disjoint, so no direct conflict exists
B.They conflict because both read different locations
C.They conflict only if T2 also writes a
D.They conflict because T1 writes c while T2 reads c βœ…
πŸ’‘ Difficulty: medium | βœ… Correct: D

πŸ“– Explanation: The location c belongs to T1’s write set and T2’s read set. A write-read overlap is a conflict because T2 may rely on a value that T1 changes before both transactions can safely commit.

Q8. A reporting workload runs many transactions that only read the same shared product catalogue. No transaction modifies the catalogue during this interval. Which statement is correct?

A.The shared reads alone do not create a read-write conflict βœ…
B.Every pair of readers must abort one transaction
C.A read-only transaction must acquire a global write lock
D.The catalogue must be copied before every read
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Read-read overlap does not invalidate either transaction’s observations because neither reader changes the shared locations. Conflict detection is needed when a competing access writes data that another transaction reads or writes.

Q9. A software transactional memory runtime records writes but omits locations read by a transaction. A concurrent transaction can then modify a value used in a calculation. What correctness risk follows?

A.The transaction becomes serializable automatically
B.Only the writing transaction can be delayed
C.Write-write conflicts become impossible
D.The first transaction may commit using a stale value without detecting the dependency βœ…
πŸ’‘ Difficulty: hard | βœ… Correct: D

πŸ“– Explanation: A transaction’s result can depend on values it read, even when it later writes another location. Without read-set tracking, a concurrent modification may go unnoticed and permit an invalid commit based on stale information.

Q10. A transaction reads x=8x = 8 and y=5y = 5, calculates z=xΓ—yz = x \times y, and prepares to write z. Before commit, another transaction changes y to 99. Validation detects the version change. What should happen?

A.Abort or retry the transaction rather than commit the stale result βœ…
B.Commit z = 40 because the calculation already finished
C.Change z to 72 without rechecking x
D.Remove y from the read set and commit
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: The calculation used y = 5, but the shared state changed before commit. Validation must reject that attempt; a retry can read the current values and recompute z without relying on a stale assumption.

Q11. A transaction reads a pointer to a customer object. The pointer value remains unchanged, but another transaction modifies the customer’s address field. Why may the first transaction still need conflict detection for that field?

A.A stable pointer freezes every field in its target object
B.Pointer reads implicitly lock all reachable memory
C.The address field is a separate shared location on which the transaction depends βœ…
D.Transactional systems track variable names rather than memory locations
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: The pointer identifies an object but does not make its contents immutable. Reading the address field creates a dependency on that field, so the runtime must track the actual memory location as well as the pointer value.

Q12. A transaction changes three shared fields and then encounters a conflict before commit. What should rollback do to its speculative updates?

A.Keep the first two changes and discard only the third
B.Publish all changes before restarting
C.Restore the pre-transaction state for the supported transactional writes βœ…
D.Convert the changes into ordinary writes
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: Rollback removes the transaction’s uncommitted memory effects so other transactions do not observe a partial result. The transaction may then be restarted from a suitable point using the current shared state.

Q13. A benchmark records 10,000 transaction attempts, of which 4,000 abort and 6,000 commit. What is the abort rate?

A.0.04
B.0.4 βœ…
C.0.6
D.4
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Abort rate equals aborted attempts divided by total attempts. Here, 4,000/10,000=0.404,000 / 10,000 = 0.40, so multiplying by 100 gives an abort rate of 40 percent. across the complete benchmark.

Q14. Two database workers repeatedly abort one another and immediately retry in near lockstep. One worker almost never commits. Which response is most likely to reduce repeated synchronized collisions?

A.Use randomized or increasing backoff before retrying βœ…
B.Remove conflict detection from both transactions
C.Increase the number of shared variables each transaction writes
D.Retry both transactions at exactly the same instant
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: Randomized or exponential backoff can break repeated timing symmetry and reduce collisions. It does not guarantee fairness, but it gives competing transactions different retry opportunities instead of recreating the same conflict pattern.

Q15. A developer observes frequent transaction aborts and concludes that every abort proves the program contains a data race. Which assessment is more accurate?

A.Every abort is caused by two simultaneous writes
B.A correct transaction can never abort
C.Some aborts can result from capacity limits, interrupts, or implementation restrictions βœ…
D.An abort means the transaction committed twice
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: Conflicts are only one possible abort cause. Hardware capacity limits, interrupts, runtime policies, and validation rules can also reject an attempt, so abort statistics alone do not prove a logical data race.

Q16. A service measures the following abort rates as concurrent transaction count increases: (1,1%), (2,3%), (4,9%), (8,28%), (12,52%), (16,70%). Which interpretation best fits the data?

A.More concurrency is reducing conflict pressure
B.Abort rate is rising sharply as contention increases βœ…
C.The system has no shared data
D.Every transaction is read-only
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The listed abort rate rises from 1 percent to 70 percent as concurrency grows. This pattern is consistent with increased overlap on shared data, causing more attempts to be rejected before commit.

Q17. A throughput plot gives these values: (1,110), (2,205), (4,365), (8,510), (12,475), (16,420), where each pair is (threads, committed transactions per second). At which thread count is throughput highest?

A.4
B.8 βœ…
C.12
D.16
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The measured throughput values rise to 510 commits per second at eight threads, then fall to 475 and 420. Therefore, the observed peak occurs at eight threads rather than at the largest thread count.

Q18. A processor provides transactional instructions and uses its cache-coherence machinery to track transactional memory accesses. Which implementation approach is being used?

A.Software transactional memory
B.File-system journaling
C.Hardware transactional memory βœ…
D.A counting semaphore
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: Hardware transactional memory uses processor mechanisms to track and manage transactional accesses, often integrating with cache coherence. Software transactional memory instead instruments memory operations through software or a managed runtime.

Q19. A team implements transactions on ordinary processors by instrumenting shared-memory reads and writes in a runtime library. Which description best matches this approach?

A.Hardware-only transactional memory
B.Software transactional memory βœ…
C.A hardware interrupt handler
D.A disk scheduling algorithm
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Software transactional memory tracks accesses through added software logic, so it does not require specialized transactional instructions. The instrumentation records dependencies and supports validation, commit, and rollback around ordinary memory operations.

Q20. A hardware transaction repeatedly aborts when it touches 300 distinct cache lines, even though no other thread accesses those lines. What is the most plausible cause?

A.A read-read conflict with every other processor
B.A violation of serializability caused by private local variables
C.A cache or transactional tracking capacity limit βœ…
D.The transaction has too few write operations
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: Hardware implementations may keep transactional read and write tracking information in bounded processor resources. A transaction can therefore exceed capacity and abort even without a logical conflict with another transaction.

Q21. A hardware transaction is interrupted by an event that the implementation cannot preserve while maintaining its speculative state. What may the implementation do?

A.Commit the transaction before checking its writes
B.Abort the transaction and restore its nontransactional execution state βœ…
C.Expose every speculative write to other processors
D.Convert its read set into a semaphore
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Some hardware implementations cannot retain a transaction across particular interrupts or context switches. They may abort it, restore the saved architectural state, and let software handle a retry or fallback path.

Q22. A performance table reports committed throughput for a global mutex and transactional execution on disjoint records: (1,100,95), (2,190,185), (4,285,340), (8,300,590), (16,305,680), where each tuple is (threads, mutex rate, transaction rate). At 8 threads, what is the transactional advantage?

A.290 more commits per second βœ…
B.290 fewer commits per second
C.Exactly twice the mutex rate
D.No measurable difference
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: At eight threads, transactional execution commits 590 per second while the mutex version commits 300. Subtracting gives 590βˆ’300=290590 - 300 = 290 additional committed transactions per second at that concurrency level.

Q23. A transaction debits an account and credits another, then sends an email before committing. The transaction later aborts. What is the main flaw?

A.The email is an external side effect that memory rollback cannot automatically undo βœ…
B.The transaction cannot update two account records
C.The email forces both account updates to commit
D.Transactional memory always duplicates network messages
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Rollback can discard supported memory updates, but it cannot normally unsend an email already delivered. External actions should generally occur only after successful commit or use a separate compensating procedure.

Q24. A transaction waits several seconds for a network response while holding speculative updates, then attempts to commit. Why is this design usually poor?

A.Network waits guarantee that all conflicts disappear
B.The transaction automatically becomes read-only while waiting
C.Long waits extend the speculative interval and may be unsupported or increase conflicts βœ…
D.A network response is always included in rollback
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: A long blocking wait keeps a transaction active while shared state can change and speculative resources remain occupied. Waiting outside the transaction and then performing a short validated update is generally safer.

Q25. A transaction updates an inventory count. A separate ordinary thread reads that count without using a compatible transactional or synchronization mechanism. Which claim is safest?

A.The ordinary read automatically joins the transaction
B.Every memory access in the process is transactional by default
C.The reader is guaranteed to observe an isolated committed state
D.The reader may fall outside the transaction’s isolation guarantees βœ…
πŸ’‘ Difficulty: hard | βœ… Correct: D

πŸ“– Explanation: Transactional guarantees apply according to the implementation’s instrumentation and mixed-access rules. An ordinary reader may not participate in the same isolation model, so access modes must be coordinated explicitly unless the implementation documents compatible behavior.

Q26. A transaction acquires an ordinary mutex. Its owner then waits for another thread whose progress depends on the transaction committing. What risk should the programmer examine?

A.A possible deadlock or progress dependency involving the lock and transaction βœ…
B.Automatic conversion of the mutex into a read-only transaction
C.Guaranteed starvation freedom for both threads
D.Elimination of every lock-order dependency
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: Combining transactions with ordinary locks can create dependencies that the transactional mechanism does not resolve automatically. If a lock holder waits for transactional progress, the design may deadlock or make no progress.

Q27. A program increments a shared statistics counter outside a transaction, then the transaction aborts while updating the main data structure. Which error can result?

A.The counter is guaranteed to decrement automatically
B.The counter can record an operation that never committed βœ…
C.The transaction must commit on its next attempt
D.The main data structure is rolled back twice
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The external counter update is not part of the aborted transaction, so it remains even though the main operation did not commit. This creates inconsistent statistics unless counting occurs after successful commit.

Q28. A student says that replacing a mutex with transactional memory eliminates all deadlocks. Which correction is best?

A.Deadlocks remain possible when transactions interact with ordinary locks or blocking operations βœ…
B.Transactional memory requires every thread to wait forever
C.A transaction always owns every lock in the process
D.Deadlock is identical to a cache capacity abort
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: Transactional execution can avoid some lock-acquisition cycles, but programs may still use ordinary locks, waits, and external resources. Dependencies involving those operations can still create deadlock or stalled progress in mixed synchronization designs.

Q29. A chart lists throughput for a high-contention shared counter: (1,900), (2,880), (4,820), (8,700), (12,560), (16,430), where each pair is (threads, commits per second). Which conclusion follows?

A.Throughput increases steadily with every added thread
B.The counter is contention-free
C.Adding threads is associated with declining committed throughput βœ…
D.The system reaches its maximum at sixteen threads
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: The measured throughput falls from 900 commits per second with one thread to 430 with sixteen. This indicates that increased contention and abort overhead outweigh the benefit of adding concurrent workers.

Q30. A team proposes transactional memory for a very short critical section that is rarely contended. The transaction runtime adds validation and bookkeeping overhead. Why may a mutex be preferable?

A.A mutex always allows conflicting updates to execute simultaneously
B.A short, low-contention operation may cost less with a simple mutex βœ…
C.Transactional memory cannot protect a single variable
D.A mutex automatically rolls back external I/O
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Transactional memory has costs for tracking, validation, and possible retries. When the critical section is short and contention is low, a conventional mutex may provide simpler protection with less overhead.

Q31. A workload contains many read-only transactions and a small number of writers. Which optimization can improve concurrency while preserving correctness?

A.Treat every read as a write to force serialization
B.Allow compatible read-only transactions to share data without unnecessary write conflicts βœ…
C.Abort every reader whenever another reader starts
D.Copy all system memory for each transaction
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Read-only transactions do not modify shared locations, so compatible implementations can let them overlap without write-write conflicts. Writers still require dependency tracking and validation to protect values observed by readers.

Q32. A transaction updates thousands of unrelated records and also writes one global audit timestamp. Transactions now conflict on that timestamp. Which redesign may reduce this hotspot while preserving audit information?

A.Make every transaction rewrite every record
B.Remove audit history without changing the requirement
C.Use batching, partitioned audit records, or a suitable post-commit logging step βœ…
D.Force all transactions to read and write the timestamp repeatedly
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: The shared timestamp creates an artificial write conflict between otherwise independent transactions. Batching or partitioning audit events, or recording them after commit, can reduce shared writes while retaining the required audit trail.

Q33. A developer runs one very large hardware transaction over 256 cache lines. It aborts repeatedly even though no competing thread touches the data. The developer concludes conflict detection is broken. Which explanation is better?

A.The tracked footprint may exceed finite hardware capacity and trigger an abort without a competing access βœ…
B.Read-only memory is never tracked by hardware
C.Disjoint data creates a conflict by definition
D.A hardware transaction cannot contain more than one memory operation
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: The conclusion overlooks implementation limits. Hardware transactional memory may use bounded caches or tracking structures for read and write sets, so an oversized transaction can abort even when no competing thread modifies its data.

Q34. A student claims optimistic transactional memory must outperform locking because it does not acquire a lock before executing. Which workload most directly disproves this claim?

A.Transactions operate on disjoint records and rarely conflict
B.Transactions perform independent read-only queries
C.Many threads repeatedly update the same popular bucket and trigger frequent aborts βœ…
D.Transactions are short and rarely overlap
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: Under heavy contention, optimistic execution can repeatedly perform work that is later discarded. A lock may serialize access more efficiently by preventing repeated conflicting attempts, so avoiding initial lock acquisition does not guarantee better performance.

Q35. Two transactions start from the same state. T1 reads x and then writes y; T2 reads y and then writes x. Both read before either writes. Why can both transactions not safely commit under a serializable model?

A.Their read-write dependencies form a cycle, so at least one attempt must be rejected or reordered βœ…
B.They access different variables, so they cannot affect each other
C.Read operations never participate in transaction conflicts
D.Both writes can be merged without checking the values read
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: T1 depends on the old x before changing y, while T2 depends on the old y before changing x. These opposing dependencies form a cycle, so committing both results cannot match a valid serial order.

Q36. A payment transaction may abort and retry. Each attempt sends a confirmation email before commit, so an aborted first attempt and a successful retry can send two messages. What is the safest design?

A.Send the email on every attempt and rely on rollback
B.Send the confirmation only after successful commit, using a reliable post-commit mechanism βœ…
C.Disable validation so the first attempt always commits
D.Move the account updates outside the transaction
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: An email sent during an attempt cannot be rolled back when that attempt aborts, and retrying may repeat it. Trigger confirmation only after a successful commit, with suitable deduplication for delivery failures.

πŸ”— Related Topics (MCQs)