Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play Deadlock Empire in Fray! #153

Merged
merged 10 commits into from
Mar 11, 2025
Merged

Play Deadlock Empire in Fray! #153

merged 10 commits into from
Mar 11, 2025

Conversation

aoli-al
Copy link
Member

@aoli-al aoli-al commented Mar 11, 2025

No description provided.

@Copilot Copilot bot review requested due to automatic review settings March 11, 2025 03:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces several translated test cases under the "Deadlock Empire" theme that simulate common concurrency pitfalls. Key changes include the addition of new concurrency test classes (e.g. CountdownEvent, CountdownEventRevisited, etc.), the use of various synchronization mechanisms (CountDownLatch, CyclicBarrier, ReentrantLock, Semaphore, condition variables), and minor documentation enhancements in the CHANGELOG.

Reviewed Changes

File Description
example/src/test/java/org/pastalab/fray/example/deadlockempire/CountdownEvent.java Adds a test demonstrating potential deadlock with CountDownLatch.
example/src/test/java/org/pastalab/fray/example/deadlockempire/CountdownEventRevisited.java Adds a test to trigger an exception by over-signaling a CountDownLatch.
example/src/test/java/org/pastalab/fray/example/deadlockempire/ConfusedCounter.java Adds a test to showcase non-atomic operations in a multithreaded context.
example/src/test/java/org/pastalab/fray/example/deadlockempire/Barrier.java Adds a test using a misconfigured CyclicBarrier with multiple threads.
example/src/test/java/org/pastalab/fray/example/deadlockempire/Deadlock.java Adds a classic deadlock demonstration using ReentrantLock.
example/src/test/java/org/pastalab/fray/example/deadlockempire/BooleanFlags.java Adds a test demonstrating weak synchronization using a boolean flag.
example/src/main/java/org/pastalab/fray/example/Main.java Introduces a simple main method for application startup.
example/src/test/java/org/pastalab/fray/example/deadlockempire/BossFight.java Adds a complex test involving semaphores and condition variables.
example/src/test/java/org/pastalab/fray/example/deadlockempire/ConditionVariables.java Adds a test demonstrating thread coordination with wait/notify.
example/src/test/java/org/pastalab/fray/example/deadlockempire/DeadlockEmpireTestBase.java Provides common helper methods for the test cases.
CHANGELOG.md Updates the changelog to reflect the new tests and debugging features.

Copilot reviewed 49 out of 49 changed files in this pull request and generated 3 comments.

while (true) {
synchronized (mutex) {
// If queue is empty, wait until producer adds something
if (queue.isEmpty()) {
Copy link
Preview

Copilot AI Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using an 'if' statement before calling wait(), consider using a 'while' loop to handle spurious wakeups in the consumer thread.

Suggested change
if (queue.isEmpty()) {
while (queue.isEmpty()) {

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
while (true) {
synchronized (mutex) {
// If queue is empty, wait until producer adds something
if (queue.isEmpty()) {
Copy link
Preview

Copilot AI Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the 'if' condition with a 'while' loop to guard against spurious wakeups in the consumer thread.

Suggested change
if (queue.isEmpty()) {
while (queue.isEmpty()) {

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Comment on lines +39 to +52
try {
fortress.acquire(); // Wait for a permit

synchronized (sanctum) {
try {
sanctum.wait(); // Wait to be notified
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

criticalSection();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Copy link
Preview

Copilot AI Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acquiring the semaphore immediately after a successful tryAcquire() may lead to a deadlock if the semaphore’s permits are mismatched; consider reviewing the semaphore usage to ensure that permits are acquired and released symmetrically.

Suggested change
try {
fortress.acquire(); // Wait for a permit
synchronized (sanctum) {
try {
sanctum.wait(); // Wait to be notified
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
criticalSection();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
synchronized (sanctum) {
try {
sanctum.wait(); // Wait to be notified
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
criticalSection();

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@aoli-al aoli-al changed the title [WIP] Play Deadlock Empire in Fray! Play Deadlock Empire in Fray! Mar 11, 2025
@aoli-al aoli-al merged commit 7af82ff into main Mar 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant