100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4,6 TrustPilot
logo-home
Exam (elaborations)

COS3721 Assignment 2 (COMPLETE ANSWERS) Semester 1 2025 - DUE 23 June 2025

Rating
-
Sold
-
Pages
25
Grade
A+
Uploaded on
23-06-2025
Written in
2024/2025

COS3721 Assignment 2 (COMPLETE ANSWERS) Semester 1 2025 - DUE 23 June 2025; 100% TRUSTED Complete, trusted solutions and explanations.










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
June 23, 2025
Number of pages
25
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

, COS3721 Assignment 2 (COMPLETE ANSWERS)
Semester 1 2025 - DUE 23 June 2025; 100%
TRUSTED Complete, trusted solutions and
explanations.
Chapter 6 – Question 01

The pseudocode below illustrates the basic push() and pop() operations of an
array-based stack.

a. What data have a race condition?

The race condition in this pseudocode arises primarily due to concurrent access
to shared data without proper synchronization. The shared data involved in the
stack operations are:

 top – the index indicating the current top of the stack.
 stack[] – the array holding the stack elements.

Race condition details:

 top is both read and modified in both push() and pop(). If two threads
call push() or pop() simultaneously, they might:
o Overwrite each other's updates to top.
o Read an outdated value of top, leading to incorrect insertion or
deletion.
 stack[top] can also be written or read at the same index by multiple
threads, leading to:
o Inconsistent or corrupted data being pushed or popped.


b. How could the race condition be fixed?

Race conditions can be fixed using mutual exclusion (mutex) mechanisms, such
as locks or semaphores, which the pseudocode tries to represent using
acquire() and release().

However, the issue here is incomplete or incorrectly scoped locking, especially
in is_empty().

Get to know the seller

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.
EstudyTube University of South Africa (Unisa)
View profile
Follow You need to be logged in order to follow users or courses
Sold
492
Member since
2 year
Number of followers
176
Documents
826
Last sold
5 days ago

If you need further assistance or have specific questions about the content, feel free to ask!

4,0

64 reviews

5
35
4
6
3
15
2
3
1
5

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

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

Student with book image

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

Alisha Student

Frequently asked questions