Skip to content

Commit

Permalink
Warn on wrong use of waiting in UI thread
Browse files Browse the repository at this point in the history
  • Loading branch information
FliegendeWurst committed Jul 17, 2023
1 parent c07a00f commit ada3542
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 4 additions & 5 deletions key.ui/src/main/java/de/uka/ilkd/key/core/Watchdog.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void start() {
private static void run() {
while (true) {
try {
Thread.sleep(10000);
Thread.sleep(20000);

Check warning on line 41 in key.ui/src/main/java/de/uka/ilkd/key/core/Watchdog.java

View workflow job for this annotation

GitHub Actions / qodana

Busy wait

Call to `Thread.sleep()` in a loop, probably busy-waiting
} catch (InterruptedException e) {
return;
}
Expand Down Expand Up @@ -66,8 +66,7 @@ private static void run() {
* Common-Cleaner TIMED_WAITING
*/

for (int i = 0; i < threads.length; i++) {
var thread = threads[i];
for (Thread thread : threads) {
if (thread == null || IGNORED_THREADS.contains(thread.getName())) {
continue;
}
Expand All @@ -81,6 +80,7 @@ private static void run() {
&& EventQueue.getCurrentEvent() == null) {
anyProgress = true; // nothing to do
}
break;
case BLOCKED:
case TIMED_WAITING:
case TERMINATED:
Expand All @@ -93,8 +93,7 @@ private static void run() {
// unfortunately, we cannot display a dialog since the UI thread is blocked...
LOGGER.error("Watchdog detected deadlock!");
LOGGER.info("Current thread state:");
for (int i = 0; i < threads.length; i++) {
var thread = threads[i];
for (Thread thread : threads) {
if (thread == null || IGNORED_THREADS.contains(thread.getName())) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void actionPerformed(ActionEvent e) {
// This method delegates the request only to the UserInterfaceControl which implements
// the functionality.
// No functionality is allowed in this method body!
getMediator().getUI().getProofControl().stopAndWaitAutoMode();
getMediator().getUI().getProofControl().stopAutoMode();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import org.key_project.util.collection.ImmutableList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A {@link ProofControl} which performs the automode in a {@link SwingWorker}.
*
Expand All @@ -32,6 +35,8 @@
// KeYMediator.
// Refactor the implementation and use events to update the user interface.
public class MediatorProofControl extends AbstractProofControl {
private static final Logger LOGGER = LoggerFactory.getLogger(MediatorProofControl.class);

private final AbstractMediatorUserInterfaceControl ui;
private AutoModeWorker worker;

Expand Down Expand Up @@ -96,6 +101,8 @@ public void stopAutoMode() {
@Override
public void waitWhileAutoMode() {
if (SwingUtilities.isEventDispatchThread()) {
LOGGER.warn("", new IllegalStateException(
"tried to block the UI thread whilst waiting for auto mode to finish"));
return; // do not block the UI thread
}
while (ui.getMediator().isInAutoMode()) { // Wait until auto mode has stopped.
Expand Down

0 comments on commit ada3542

Please sign in to comment.