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

Replace threadpool with Rust's Standard Library for Parallel Execution #9932

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

notJoon
Copy link

@notJoon notJoon commented Mar 19, 2024

Description

In the existing run_parallel, the threadpool package was used to handle parallel tasks. However, this package was only used in this function, and it has been determined that the standard library of Rust can adequately address these needs. Therefore, modifications have been made to no longer use this library.

To replicate the functionality previously provided by threadpool, the following changes have been made:

  1. For each GrammarConfiguration instance, std::thread::spawn is used to create a separate thread.
  2. std::sync::mpsc::channel is used to collect the results of tasks executed in each thread.
  3. The process waits until all threads have finished and then collects the results from each thread.

Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

Std has a threadpool too. Spawning threads manually isn't ideal

@the-mikedavis the-mikedavis added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 19, 2024
@archseer
Copy link
Member

Is there a threadpool in std? I wasn't able to find one. Either way, the reason I didn't implement this with threads directly in the first place is that with a pool we can limit concurrency to a fixed amount of threads. We don't want to build all 100+ grammars at once concurrently

@pascalkuthe
Copy link
Member

Is there a threadpool in std? I wasn't able to find one. Either way, the reason I didn't implement this with threads directly in the first place is that with a pool we can limit concurrency to a fixed amount of threads. We don't want to build all 100+ grammars at once concurrently

i meant the scope thread api. You can create 1 scope/thread per core, each with a reference to a channel and then pull from that channel. That is what ingore does internally (its more fancy these days as they recently added workstealing but unitl recently it just used a simple channel). So the API is not quite equivalent but its pretty close (just a couple lok exta)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants