docs: add theoretical questions on atomic variables, synchronization, scalability, and deadlocks
This commit is contained in:
@@ -4,39 +4,72 @@
|
||||
## 📋 Introduction
|
||||
This assignment is divided into two main sections:
|
||||
|
||||
- **Theoretical Questions**: You are asked to answer questions about multithreading concepts.
|
||||
<br>
|
||||
<br>
|
||||
- **Practical Project**: You are asked to implement a banking system that performs concurrent operations using multithreading. The main goal of the exercise is handling deadlocks and race conditions so that the program performs correctly.
|
||||
### **Theoretical Questions**:
|
||||
- You are asked to answer questions about multithreading concepts.
|
||||
|
||||
### **Practical Project**:
|
||||
- You are asked to implement a banking system that performs concurrent operations using multithreading. The main goal of the exercise is handling deadlocks and race conditions so that the program performs correctly.
|
||||
|
||||
---
|
||||
|
||||
## 🧠 Theoretical Questions
|
||||
|
||||
**Note**:
|
||||
Write your answers in a Markdown file (e.g. Answers.md) and place it in the root directory of your forked repository.
|
||||
### **Note**:
|
||||
**Write your answers in a Markdown file (e.g. Answers.md) and place it in the root directory of your forked repository.**
|
||||
|
||||
---
|
||||
**1-** What are atomic variables? Explain their purpose and how they differ from ordinary (non‑atomic) variables.
|
||||
|
||||
**2-** Name at least four classes from the java.util.concurrent.atomic package that provide atomic operations for different data types. For one of them, briefly describe a typical use case.
|
||||
|
||||
**3-** Compare locks with atomic variables. In which scenarios is using a lock a better choice than an atomic variable, and vice versa?
|
||||
|
||||
**4-** Deadlocks often only appear in production, not during testing. Explain why this might happen from a thread‑scheduling perspective. Describe two strategies a developer can use to increase the likelihood of exposing deadlocks during testing.
|
||||
|
||||
**5-** Obstruction‑freedom, lock‑freedom, and wait‑freedom are three classic non‑blocking progress guarantees. Define each guarantee, then Rank them from weakest to strongest. Using AtomicInteger.incrementAndGet() as an example, explain which guarantee it provides.
|
||||
### ⚛️ Atomic Variables & Synchronization
|
||||
|
||||
---
|
||||
|
||||
### 🎯Bonus Questions and Tasks:
|
||||
**1-** Explain the fundamental differences between a thread and a process. Then compare multithreaded programming and multi‑process programming with respect to how they handle (or are prone to) deadlocks and race conditions.
|
||||
**1 -** What are atomic variables?
|
||||
|
||||
Explain their purpose and how they differ from ordinary (non-atomic) variables.
|
||||
|
||||
**2 -** Name at least four classes from the `java.util.concurrent.atomic` package that provide atomic operations for different data types.
|
||||
|
||||
For one of them, briefly describe a typical use case.
|
||||
|
||||
**3 -** Compare locks with atomic variables.
|
||||
|
||||
In which scenarios is using a lock a better choice than an atomic variable, and vice versa?
|
||||
|
||||
#### 🎯Bonus Task:
|
||||
|
||||
**2-**
|
||||
Write a small Java program that concurrently increments a normal int variable and an AtomicInteger variable from multiple threads. Print the final values of both variables to demonstrate that the atomic variable produces the correct result, while the normal variable may show an inconsistent value due to a race condition.
|
||||
|
||||
### 🔒 Locks & Concurrent Design
|
||||
|
||||
---
|
||||
## Practical Assignment 💻
|
||||
|
||||
**4 -** A program is completely free of race conditions but still performs poorly under high contention.
|
||||
|
||||
Explain how this situation can occur.
|
||||
|
||||
Discuss at least three concurrency-related factors that may limit scalability even when correctness is guaranteed.
|
||||
|
||||
**5 -** Many concurrent systems experience performance degradation as the number of threads increases.
|
||||
|
||||
Explain why adding more threads does not always improve performance.
|
||||
|
||||
Your answer should discuss concepts such as:
|
||||
|
||||
Context switching
|
||||
Contention
|
||||
Cache coherence
|
||||
Synchronization overhead
|
||||
|
||||
### ⚠️ Deadlocks
|
||||
|
||||
---
|
||||
|
||||
**6 -** Deadlocks often only appear in production, not during testing.
|
||||
|
||||
Explain why this might happen from a thread-scheduling perspective.
|
||||
|
||||
Describe two strategies a developer can use to increase the likelihood of exposing deadlocks during testing.
|
||||
|
||||
---
|
||||
## 💻 Practical Project
|
||||
|
||||
## 🏦 Advanced Banking & Transaction Processing System
|
||||
|
||||
|
||||
Reference in New Issue
Block a user