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

Fix AsyncFileDialog blocking on Windows #191

Merged
merged 1 commit into from
May 5, 2024

Conversation

valadaptive
Copy link
Contributor

ThreadFuture would send a mutex to the thread it spawned, which would then immediately lock that mutex to pass it into whichever blocking callback wanted to write to the data inside it.

Meanwhile, calling poll on that ThreadFuture would also lock that mutex, blocking until the spawned thread finished running and hence defeating the entire purpose of using a future, and possibly even causing the spawned thread to block instead if poll was called fast enough, causing a deadlock.

This is fixed by separating the data and waker into two separate mutexes; calling poll always sets the waker but only try_locks the mutex for data.

ThreadFuture would send a mutex to the thread it spawned, which would
then immediately lock that mutex to pass it into whichever blocking
callback wanted to write to the data inside it. Meanwhile, calling
`poll` on that ThreadFuture would *also* lock that mutex, blocking
until the spawned thread finished running and hence defeating the entire
purpose of using a future, and possibly even causing the *spawned*
thread to block instead if `poll` was called fast enough, causing a
deadlock. This is fixed by separating the `data` and `waker` into two
separate mutexes; calling `poll` always sets the `waker` but doesn't
lock the mutex for `data`.
Copy link
Owner

@PolyMeilex PolyMeilex left a comment

Choose a reason for hiding this comment

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

Sounds good, thanks!

@PolyMeilex PolyMeilex merged commit 6f9062e into PolyMeilex:master May 5, 2024
13 checks 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.

2 participants