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

feat: alter clipboard thread to move all clipboard loading from main thread #2867

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dordsor21
Copy link
Member

No description provided.

@dordsor21 dordsor21 requested a review from a team as a code owner August 1, 2024 20:25
@github-actions github-actions bot added the Feature This PR adds a new feature label Aug 1, 2024
@dordsor21
Copy link
Member Author

Currently untested

}
return bukkitPlayer;
};
TaskManager.taskManager().sync(task);
Copy link
Member

Choose a reason for hiding this comment

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

This can cause deadlocks when the server thread is waiting for the current thread. What's the intention behind it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The task manager method here will run the given task immediately if it's on the main thread

Copy link
Member

Choose a reason for hiding this comment

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

Yes but it doesn't know if the main thread is blocked by the current thread

@Override
public Thread newThread(@Nonnull Runnable r) {
return defaultFactory.newThread(() -> {
IS_UUID_KEYED_EXECUTOR_THREAD.set(true);
Copy link
Member

Choose a reason for hiding this comment

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

What's the idea here? I'd assume every thread in this thread pool is always a uuid keyed executor thread? Would it be enough to subtype Thread and do an instanceof check where needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It needs to be accessible from runners within the thread itself. I didn't want to offload to an async thread from main thread needlessly to then run on this thread again. I suppose checking if the current thread is an instance of subtype would be cleaner


@Override
public void loadClipboardFromDisk() {
if (clipboardLoading.isWriteLocked()) {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we only use the write lock. Can't we use a different lock then (or a Semaphore if you want to unlock from a different thread)? Besides that, I think there might be a race condition where the write lock is not locked at this call but below the if. If that happens on the main thread, we stall the main thread.

@dordsor21 dordsor21 force-pushed the feat/alter-clipboard-thread-usage branch from 203948d to a71c3b4 Compare September 29, 2024 11:38
@dordsor21 dordsor21 force-pushed the feat/alter-clipboard-thread-usage branch from a71c3b4 to e6481ee Compare September 29, 2024 11:41
@dordsor21 dordsor21 force-pushed the feat/alter-clipboard-thread-usage branch from 7ab49c8 to e1bd063 Compare September 29, 2024 13:18
@dordsor21 dordsor21 requested review from SirYwell and a team September 29, 2024 13:18
Comment on lines +514 to +516
CompletableFuture.completedFuture(callable.call());
} catch (Throwable t) {
CompletableFuture.failedFuture(t);
Copy link
Member

Choose a reason for hiding this comment

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

Those are missing returns, causing a deadlock when joining - maybe the the return below should be in an explicit else branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature This PR adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants