Skip to content

Conversation

@Zaggy1024
Copy link
Contributor

@Zaggy1024 Zaggy1024 commented Dec 5, 2025

Since the event loop has a very specifically scoped lifetime, we can't ensure that it outlives threads that hold a reference to it without blocking the thread that owns it. In order to make threads use the event loop safely, we now have an atomically ref-counted EventLoopWeak class that can be passed off to threads to safely post events/callbacks to it.

Another possibility was to use an RWLock per event loop that each thread holds a read lock on, while ~EventLoop() uses a write lock to block and prevent it being destroyed until all its threads exit. However, media data providers don't receive a signal to exit due to the GC heap being intentionally leaked, so the process never actually exits. It would be possible to specifically drop the reference to PlaybackManager in HTMLMediaElement in order to make those data providers die on their own, but that doesn't help prevent this problem in other cases where it may arise.

Since the event loop has a very specifically scoped lifetime, we can't
ensure that it outlives threads that hold a reference to it without
blocking the thread that owns it. In order to make threads use the
event loop safely, we now have an atomically ref-counted EventLoopWeak
class that can be passed off to threads to safely post events/callbacks
to it.

Another possibility was to use an RWLock per event loop that each
thread holds a read lock on, while ~EventLoop() uses a write lock to
block and prevent it being destroyed until all its threads exit.
However, media data providers don't receive a signal to exit due to the
GC heap being intentionally leaked, so the process never actually
exits. It would be possible to specifically drop the reference to
PlaybackManager in HTMLMediaElement in order to make those data
providers die on their own, but that doesn't help prevent this problem
in other cases where it may arise.
@Zaggy1024
Copy link
Contributor Author

Zaggy1024 commented Dec 5, 2025

Looks like the changes to BackgroundThread are causing a rare deadlock (or more likely infinite spin) in some test webviews, I'll have to do some further investigation...

@Zaggy1024 Zaggy1024 marked this pull request as draft December 5, 2025 23:09
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