Skip to content

Fix AsyncFileDialog blocking on Windows#191

Merged
PolyMeilex merged 1 commit intoPolyMeilex:masterfrom
valadaptive:fix-async
May 5, 2024
Merged

Fix AsyncFileDialog blocking on Windows#191
PolyMeilex merged 1 commit intoPolyMeilex:masterfrom
valadaptive:fix-async

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
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