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: add clear_tasks() #69

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

samangh
Copy link
Contributor

@samangh samangh commented Aug 5, 2024

@DeveloperPaul123 Firstly, thanks for this nice library. I'm glad that mentioned it on reddit. I was thinking of implementing my own thread pool, but you've definitely done a better job than I could have!

I think it would be useful to have a function for clearing all the tasks in the thread pool. This could be useful when, for example, one loads the thread pool with a list of tasks but then needs to clear them if an error/exception is thrown somewhere.

Note that this not fool-proof, for example a running task could add other tasks to the pool. Or alternatively, during the for loop, one thread (which just had it's task list cleared) could steal a thread from another task. But I didn't see a way of getting around these edge cases without adding another mutex

Of course, this is just one possible way of doing this. Please feel to do with the PR as you wish :-).

@samangh samangh force-pushed the dev/add-clear_tasks branch 2 times, most recently from a32df2b to e0061d5 Compare August 6, 2024 07:44
@DeveloperPaul123
Copy link
Owner

@samangh Hello! 👋 Thank you for the kind words and the PR! This is an interesting feature/use case and not something I had considered in the past.

It looks like the changes are simple, but I agree that this could cause some issues in practice with race conditions. At a minimum, for me to consider merging this PR, I would appreciate it if you could add some unit tests for the new feature. Both for the queue and the thread pool.

Thanks!

@samangh
Copy link
Contributor Author

samangh commented Aug 10, 2024

@DeveloperPaul123 Thanks for the reply. I've added unit tests to both the queue and the thread pool, I hope they make sense.

@samangh samangh force-pushed the dev/add-clear_tasks branch from 5648a19 to 62cecbe Compare August 10, 2024 20:25
@DeveloperPaul123
Copy link
Owner

@samangh Looks like most of the CI builds are failing due to some warnings. Could you please address these?

Copy link

@samangh samangh force-pushed the dev/add-clear_tasks branch 4 times, most recently from ae1526b to 43d2d29 Compare August 14, 2024 18:21
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.52%. Comparing base (cee2fce) to head (43d2d29).
Report is 25 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #69      +/-   ##
==========================================
+ Coverage   98.07%   98.52%   +0.45%     
==========================================
  Files           2        2              
  Lines         104      136      +32     
==========================================
+ Hits          102      134      +32     
  Misses          2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@samangh samangh force-pushed the dev/add-clear_tasks branch from 43d2d29 to 11976ab Compare August 14, 2024 19:13
@samangh
Copy link
Contributor Author

samangh commented Aug 14, 2024

@DeveloperPaul123 Thanks for letting me know. I've fixed the tests, they should pass now.

@samangh samangh force-pushed the dev/add-clear_tasks branch from 11976ab to 4a853e1 Compare August 14, 2024 19:44
Copy link
Owner

@DeveloperPaul123 DeveloperPaul123 left a comment

Choose a reason for hiding this comment

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

Looks good to me! Nice work 👍

@DeveloperPaul123 DeveloperPaul123 merged commit 9b0557d into DeveloperPaul123:master Aug 15, 2024
12 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