{"id":15579034,"url":"https://github.com/dapper91/thread_pool_executor","last_synced_at":"2025-04-24T01:27:43.796Z","repository":{"id":96973451,"uuid":"127163761","full_name":"dapper91/thread_pool_executor","owner":"dapper91","description":"C++ Thread Pool Executor","archived":false,"fork":false,"pushed_at":"2018-03-31T19:46:55.000Z","size":14,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T05:41:12.299Z","etag":null,"topics":["concurrent","cpp","threadpoolexecutor"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dapper91.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-28T15:49:50.000Z","updated_at":"2025-01-19T21:56:08.000Z","dependencies_parsed_at":"2023-03-15T11:00:50.010Z","dependency_job_id":null,"html_url":"https://github.com/dapper91/thread_pool_executor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapper91%2Fthread_pool_executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapper91%2Fthread_pool_executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapper91%2Fthread_pool_executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapper91%2Fthread_pool_executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dapper91","download_url":"https://codeload.github.com/dapper91/thread_pool_executor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250543217,"owners_count":21447854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrent","cpp","threadpoolexecutor"],"created_at":"2024-10-02T19:13:38.603Z","updated_at":"2025-04-24T01:27:43.777Z","avatar_url":"https://github.com/dapper91.png","language":"C++","readme":"# C++ Thread Pool Executor\n\nPure C++14 Thread Pool Executor. No external dependencies.\n\n## Dependencies\n\n* C++14\n\n\n\n## Usage example\n\n```c++\n\n#include \u003ciostream\u003e\n#include \u003csstream\u003e\n#include \u003ciomanip\u003e\n#include \u003cfunctional\u003e\n#include \u003cthread\u003e\n#include \u003catomic\u003e\n#include \u003crandom\u003e\n\n#include \"thread_pool_executor.hpp\"\n\nusing namespace std::chrono_literals;\n\nstd::random_device rand_dev;\n\nthread_local size_t worker_idx = -1; \nstd::atomic_size_t workers_cnt;\n\nvoid task(size_t i)\n{\n    if (worker_idx == -1) {\n        worker_idx = ++workers_cnt;\n    }\n    std::stringstream message;\n\n    std::uniform_int_distribution\u003cint\u003e dist(0, 10);\n    std::this_thread::sleep_for(std::chrono::seconds(dist(rand_dev)));\n\n    message \u003c\u003c \"[\" \u003c\u003c \"worker-\" \u003c\u003c std::setfill('0') \u003c\u003c std::setw(2) \u003c\u003c worker_idx \u003c\u003c \"]\" \u003c\u003c \"\\t\" \n            \u003c\u003c \"task-\" \u003c\u003c std::setw(2) \u003c\u003c i \u003c\u003c \" has been compleated.\" \u003c\u003c std::endl;\n    std::cout \u003c\u003c message.str();\n}\n\nint main()\n{\n    std::uniform_int_distribution\u003cint\u003e dist(0, 500);\n\n    size_t pool_size = 4;\n    size_t max_pool_size = 16;\n    size_t max_queue_size = 64;\n    std::chrono::seconds keep_alive_time = 5s;\n\n    ThreadPoolExecutor executor(pool_size, max_pool_size, keep_alive_time, max_queue_size);\n\n    for (size_t i = 0; i \u003c 100; ++i) {\n        executor.submit(std::bind(task, i));\n        std::this_thread::sleep_for(std::chrono::milliseconds(dist(rand_dev)));\n    }\n\n    executor.shutdown();\n    executor.wait();\n\n    return 0;\n}\n\n```\n\n\n## API\n\n### Constructor\n\nCreates a thread pool executor instance and starts `pool_size` threads.\n\nConstructor arguments:\n\n- `pool_size` - the number of threads to keep in the pool, even if they are idle\n- `max_pool_size` - the maximum number of threads to allow in the pool\n- `keep_alive_time` - when the number of threads is greater than the `pool_size`, this is the maximum time that excess idle threads will wait for new tasks before terminating\n- `max_queue_size` - the maximum number of tasks in the executor queue, if the `max_queue_size` is reached `QueueIsFull` exception will be thrown\n\n### submit\n\nExecutes the given task sometime in the future.\n\nMethod arguments:\n\n- `func` - the task to execute\n\n### is_shutdown\n\nReturns true if this executor has been shut down.\n\n### shutdown\n\nInitiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.\n\n### terminate\n\nInitiates a termination process in which previously submitted tasks waiting in the queue will be destroyed, no new tasks will be accepted.\n\n### is_terminated\n\nReturns true if this executor has been is_terminated.\n\n### wait\n\nBlocks until all tasks have completed execution after a shutdown request, or the timeout occurs, whichever happens first.\n\nMethod arguments:\n\n- `timeout` - the maximum time to wait\n\n## License\n\nPublic Domain License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdapper91%2Fthread_pool_executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdapper91%2Fthread_pool_executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdapper91%2Fthread_pool_executor/lists"}