diff options
author | Stanislav Kirillov <staskirillov@gmail.com> | 2022-02-10 16:46:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:07 +0300 |
commit | 92fe2b1e7bc79f7b95adef61714fc003f6ea4a1c (patch) | |
tree | 817034f4ca57c9f841bb047ec94630c2e78a2b1d /library/cpp/threading/local_executor/README.md | |
parent | 53c76da6d9f6cc5a17f6029df396f0e3bc1ff47d (diff) | |
download | ydb-92fe2b1e7bc79f7b95adef61714fc003f6ea4a1c.tar.gz |
Restoring authorship annotation for Stanislav Kirillov <staskirillov@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/threading/local_executor/README.md')
-rw-r--r-- | library/cpp/threading/local_executor/README.md | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/library/cpp/threading/local_executor/README.md b/library/cpp/threading/local_executor/README.md index aaad2e2986..0fdd6f6173 100644 --- a/library/cpp/threading/local_executor/README.md +++ b/library/cpp/threading/local_executor/README.md @@ -1,23 +1,23 @@ -# Library for parallel task execution in thread pool - -This library allows easy parallelization of existing code and cycles. -It provides `NPar::TLocalExecutor` class and `NPar::LocalExecutor()` singleton accessor. +# Library for parallel task execution in thread pool + +This library allows easy parallelization of existing code and cycles. +It provides `NPar::TLocalExecutor` class and `NPar::LocalExecutor()` singleton accessor. At start, `TLocalExecutor` has no threads in thread pool and all async tasks will be queued for later execution when extra threads appear. -All tasks should be `NPar::ILocallyExecutable` child class or function equal to `std::function<void(int)>` - -## TLocalExecutor methods - -`TLocalExecutor::Run(int threadcount)` - add threads to thread pool (**WARNING!** `Run(threadcount)` will *add* `threadcount` threads to pool) - -`void TLocalExecutor::Exec(TLocallyExecutableFunction exec, int id, int flags)` - run one task and pass id as task function input, flags - bitmask composition of: - -- `TLocalExecutor::HIGH_PRIORITY = 0` - put task in high priority queue -- `TLocalExecutor::MED_PRIORITY = 1` - put task in medium priority queue -- `TLocalExecutor::LOW_PRIORITY = 2` - put task in low priority queue -- `TLocalExecutor::WAIT_COMPLETE = 4` - wait for task completion - +All tasks should be `NPar::ILocallyExecutable` child class or function equal to `std::function<void(int)>` + +## TLocalExecutor methods + +`TLocalExecutor::Run(int threadcount)` - add threads to thread pool (**WARNING!** `Run(threadcount)` will *add* `threadcount` threads to pool) + +`void TLocalExecutor::Exec(TLocallyExecutableFunction exec, int id, int flags)` - run one task and pass id as task function input, flags - bitmask composition of: + +- `TLocalExecutor::HIGH_PRIORITY = 0` - put task in high priority queue +- `TLocalExecutor::MED_PRIORITY = 1` - put task in medium priority queue +- `TLocalExecutor::LOW_PRIORITY = 2` - put task in low priority queue +- `TLocalExecutor::WAIT_COMPLETE = 4` - wait for task completion + `void TLocalExecutor::ExecRange(TLocallyExecutableFunction exec, TExecRangeParams blockParams, int flags);` - run range of tasks `[TExecRangeParams::FirstId, TExecRangeParams::LastId).` - + `flags` is the same as for `TLocalExecutor::Exec`. `TExecRangeParams` is a structure that describes the range. @@ -33,32 +33,32 @@ It is also possible to partition range of tasks in consequtive blocks and execut the range of tasks into consequtive blocks of approximately given size, or of size calculated by partitioning the range into approximately equal size blocks of given count. -## Examples - -### Simple task async exec with medium priority - -```cpp -using namespace NPar; - -LocalExecutor().Run(4); -TEvent event; -LocalExecutor().Exec([](int) { - SomeFunc(); - event.Signal(); -}, 0, TLocalExecutor::MED_PRIORITY); - -SomeOtherCode(); -event.WaitI(); -``` - -### Execute task range and wait completion - -```cpp -using namespace NPar; - -LocalExecutor().Run(4); +## Examples + +### Simple task async exec with medium priority + +```cpp +using namespace NPar; + +LocalExecutor().Run(4); +TEvent event; +LocalExecutor().Exec([](int) { + SomeFunc(); + event.Signal(); +}, 0, TLocalExecutor::MED_PRIORITY); + +SomeOtherCode(); +event.WaitI(); +``` + +### Execute task range and wait completion + +```cpp +using namespace NPar; + +LocalExecutor().Run(4); LocalExecutor().ExecRange([](int id) { - SomeFunc(id); + SomeFunc(id); }, TExecRangeParams(0, 10), TLocalExecutor::WAIT_COMPLETE | TLocalExecutor::MED_PRIORITY); ``` |