From 5c7ddec694a9fd4e11ca3cfcfa3949df4082cff6 Mon Sep 17 00:00:00 2001 From: peyman Date: Thu, 4 Jun 2026 16:57:26 +0330 Subject: [PATCH 1/2] Theorical questions added --- README.md | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 25097ba..4ad37b5 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,35 @@ # HW-09 — Advanced Multithreading --- +## 📋 Introduction +This assignment is divided into two main sections: -## Theoretical Questions 📝 +- **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. +--- +**1-** What are atomic variables? Explain their purpose and how they differ from ordinary (non‑atomic) variables. -## TODO +**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. + +--- + +### 🎯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. + +**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. --- ## Practical Assignment 💻 From 1df0d7b7216a8daf5c7accd520723348070855d7 Mon Sep 17 00:00:00 2001 From: peyman Date: Thu, 4 Jun 2026 17:04:12 +0330 Subject: [PATCH 2/2] Theorical questions updated --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 4ad37b5..8794aad 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,14 @@ This assignment is divided into two main sections:

- **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. + --- **1-** What are atomic variables? Explain their purpose and how they differ from ordinary (non‑atomic) variables. @@ -30,6 +34,7 @@ Write your answers in a Markdown file (e.g. Answers.md) and place it in the root **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. + --- ## Practical Assignment 💻