Skip to content

Exit worker threads immediately when their input channels disconnect#5

Merged
DerFetzer merged 1 commit intoDerFetzer:mainfrom
faern:cleanly-exit-worker-threads
Feb 6, 2025
Merged

Exit worker threads immediately when their input channels disconnect#5
DerFetzer merged 1 commit intoDerFetzer:mainfrom
faern:cleanly-exit-worker-threads

Conversation

@faern
Copy link
Copy Markdown
Contributor

@faern faern commented Feb 6, 2025

This stops the worker threads from sitting in a tight busy loop consuming 100% CPU if the channels they listen for input on are ever dropped.

This can for example happen if the thread owning the sender panics. Even if the panic does result in the process eventually aborting, this stops the worker threads from going crazy while the shut down happens.

I tested this by inserting a panic in the main thread. And indeed, the camera thread were doing a few thousand loops before the process died. This way should be more efficient and cleaner.

The diff is 99% indentation changes only. The only real change is that the loop + if let was joined into a while let. And then a log::debug! was added at the end of both run methods.

This stops the worker threads from sitting in a tight busy loop
consuming 100% CPU if the channels they listen for input on are ever
dropped.

This can for example happen if the thread owning the sender panics. Even
if the panic does result in the process eventually aborting, this stops
the worker threads to go crazy while the shut down happens.
@DerFetzer
Copy link
Copy Markdown
Owner

Thank you very much!
The diff looks nasty at first glance, but of course this is much better.
I should have a look at the whole code again having some more years of experience with rust, now. ;)

@DerFetzer DerFetzer merged commit db43f25 into DerFetzer:main Feb 6, 2025
3 checks passed
@faern faern deleted the cleanly-exit-worker-threads branch February 7, 2025 04:41
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