COS3721
Assignment 2 2025
Detailed Solutions, References & Explanations
Unique number:
Due Date: 23 June 2025
Chapter 6 – Question 01
a. What data have a race condition?
In the given pseudocode for an array-based stack in a concurrent environment, the variable top is
subject to a race condition. This variable is accessed and modified in both the push() and pop()
operations. If two threads execute either of these functions at the same time without proper
synchronization, they may read and update the top value simultaneously, leading to inconsistent
or corrupted stack state (e.g. data loss or overwriting).
b. How could the race condition be fixed?
The pseudocode already attempts to use acquire() and release() to create a critical section,
suggesting some kind of locking mechanism (like a mutex or semaphore). However, to properly
fix the race condition:
Terms of use
Ensure that acquire() is implemented using a thread-safe mutual
By making use ofexclusion mechanism
this document you agree to:
Use this document as a guide for learning, comparison and reference purpose,
Terms of use
Not to duplicate, reproduce and/or misrepresent the contents of this document as your own work,
By making use of this document you agree to:
Use this document
Fully accept the consequences
solely as a guide forshould you plagiarise
learning, reference,or and
misuse this document.
comparison purposes,
Ensure originality of your own work, and fully accept the consequences should you plagiarise or misuse this document.
Comply with all relevant standards, guidelines, regulations, and legislation governing academic and written work.
Disclaimer
Great care has been taken in the preparation of this document; however, the contents are provided "as is" without any express or
implied representations or warranties. The author accepts no responsibility or liability for any actions taken based on the
information contained within this document. This document is intended solely for comparison, research, and reference purposes.
Reproduction, resale, or transmission of any part of this document, in any form or by any means, is strictly prohibited.
Assignment 2 2025
Detailed Solutions, References & Explanations
Unique number:
Due Date: 23 June 2025
Chapter 6 – Question 01
a. What data have a race condition?
In the given pseudocode for an array-based stack in a concurrent environment, the variable top is
subject to a race condition. This variable is accessed and modified in both the push() and pop()
operations. If two threads execute either of these functions at the same time without proper
synchronization, they may read and update the top value simultaneously, leading to inconsistent
or corrupted stack state (e.g. data loss or overwriting).
b. How could the race condition be fixed?
The pseudocode already attempts to use acquire() and release() to create a critical section,
suggesting some kind of locking mechanism (like a mutex or semaphore). However, to properly
fix the race condition:
Terms of use
Ensure that acquire() is implemented using a thread-safe mutual
By making use ofexclusion mechanism
this document you agree to:
Use this document as a guide for learning, comparison and reference purpose,
Terms of use
Not to duplicate, reproduce and/or misrepresent the contents of this document as your own work,
By making use of this document you agree to:
Use this document
Fully accept the consequences
solely as a guide forshould you plagiarise
learning, reference,or and
misuse this document.
comparison purposes,
Ensure originality of your own work, and fully accept the consequences should you plagiarise or misuse this document.
Comply with all relevant standards, guidelines, regulations, and legislation governing academic and written work.
Disclaimer
Great care has been taken in the preparation of this document; however, the contents are provided "as is" without any express or
implied representations or warranties. The author accepts no responsibility or liability for any actions taken based on the
information contained within this document. This document is intended solely for comparison, research, and reference purposes.
Reproduction, resale, or transmission of any part of this document, in any form or by any means, is strictly prohibited.