{"id":13730017,"url":"https://github.com/Fdhvdu/ThreadPool","last_synced_at":"2025-05-08T02:31:01.665Z","repository":{"id":56733817,"uuid":"47162504","full_name":"Fdhvdu/ThreadPool","owner":"Fdhvdu","description":"A fastest, exception-safety and pure C++17 thread pool.","archived":false,"fork":false,"pushed_at":"2019-07-29T14:37:57.000Z","size":283,"stargazers_count":131,"open_issues_count":2,"forks_count":23,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-07T07:28:31.991Z","etag":null,"topics":["c-plus-plus-17","fastest","performance-comparison","thread-pool"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fdhvdu.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}},"created_at":"2015-12-01T03:17:24.000Z","updated_at":"2024-09-14T03:33:24.000Z","dependencies_parsed_at":"2022-08-16T00:50:22.520Z","dependency_job_id":null,"html_url":"https://github.com/Fdhvdu/ThreadPool","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/Fdhvdu%2FThreadPool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fdhvdu%2FThreadPool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fdhvdu%2FThreadPool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fdhvdu%2FThreadPool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fdhvdu","download_url":"https://codeload.github.com/Fdhvdu/ThreadPool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252986671,"owners_count":21836203,"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":["c-plus-plus-17","fastest","performance-comparison","thread-pool"],"created_at":"2024-08-03T02:01:08.797Z","updated_at":"2025-05-08T02:31:01.365Z","avatar_url":"https://github.com/Fdhvdu.png","language":"C++","readme":"# Warnings\r\nSince commit `468129863ec65c0b4ede02e8581bea682351a6d2`, I move ThreadPool to C++17. (To use `std::apply`.)\u003cbr\u003e\r\nIn addition, **the rule of passing parameters to ThreadPool is different.**\u003cbr\u003e\r\nUnlike before, which uses `std::bind`, **ThreadPool will not copy anything right now.**\u003cbr\u003e\r\nAll of ThreadPool does is forward (**no decay**).\u003cbr\u003e\r\nThis means you have to copy arguments by yourself before passing it to ThreadPool.\u003cbr\u003e\r\nBelow is demonstration,\r\n\r\n\tvoid test(int \u0026i)\r\n\t{\r\n\t\ti=10;\r\n\t}\r\n\r\n\tint main()\r\n\t{\r\n\t\tint i(0);\r\n\t\tCThreadPool tp;\r\n\t\ttp.join(tp.add(test,i));\r\n\r\n\t\t//before commit f66048ed999aa1b50dc956c4a728ff565042d761\r\n\t\tcout\u003c\u003ci\u003c\u003cendl;\t//0\r\n\r\n\t\t//since commit f66048ed999aa1b50dc956c4a728ff565042d761\r\n\t\tcout\u003c\u003ci\u003c\u003cendl;\t//10\r\n\t}\r\n# Contents\r\n[Introduction](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#introduction)\u003cbr\u003e\r\n[Class view](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#class-view)\u003cbr\u003e\r\n[Performance comparison](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#performance-comparison)\u003cbr\u003e\r\n[Compiler](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#compiler)\u003cbr\u003e\r\n[How to compile](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#how-to-compile)\u003cbr\u003e\r\n[Compilation errors?](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#compilation-errors)\u003cbr\u003e\r\n[Tutorial](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#tutorial)\u003cbr\u003e\r\n[Future work](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#future-work)\r\n# Introduction\r\nThis is a pure (which means it doesn't depend on any platform) and exception-safety C++ threadpool (so far, there is no standard threadpool in C++).\u003cbr\u003e\r\nThe goal of this project is to provide a `fastest`, `beautiful` and `easy-to-use` C++ threadpool library.\r\n# Class view\r\nTwo classes\r\n\r\n\tCThreadPool, including the member function\r\n\t\tthread_id    add(Func \u0026\u0026,Args \u0026\u0026...)\r\n\t\tvoid         add_and_detach(Func \u0026\u0026,Args \u0026\u0026...)\r\n\t\tsize_type    empty() const noexcept\r\n\t\tvoid         join(thread_id)\r\n\t\tvoid         join_all()\r\n\t\tbool         joinable(thread_id) const\r\n\t\tsize_type    size() const noexcept\r\n\t\tvoid         wait_until_all_usable() const\r\n\t\t\r\n\tCThreadPool_Ret, including the member function\r\n\t\tthread_id    add(Func \u0026\u0026,Args \u0026\u0026...)\r\n\t\tsize_type    empty() const noexcept\r\n\t\tRet          get(thread_id)\r\n\t\tsize_type    size() const noexcept\r\n\t\tbool         valid(thread_id) const\r\n\t\tvoid         wait(thread_id) const\r\n\t\tvoid         wait_all() const\r\nUse the CThreadPool_Ret when you want to get the return value of function.\u003cbr\u003e\r\nUse the CThreadPool when you don't care the return value of function.\u003cbr\u003e\r\n`CThreadPool::add_and_detach` is faster (very) than `CThreadPool_Ret::add`.\r\n# Performance comparison\r\n[progschj/ThreadPool](https://github.com/progschj/ThreadPool), see [Comparison](comparison/README.md#result).\u003cbr\u003e\r\n[Tyler-Hardin/thread_pool](https://github.com/Tyler-Hardin/thread_pool), see [Comparison](comparison/README.md#result).\u003cbr\u003e\r\nP.S. About [bilash/threadpool](https://github.com/bilash/threadpool), I don't want to test a C-like code.\u003cbr\u003e\r\nP.S. [nbsdx/ThreadPool](https://github.com/nbsdx/ThreadPool) cannot pass testing, see [README](comparison/nbsdx/README.md#warning).\u003cbr\u003e\r\nP.S. [philipphenkel/threadpool](https://github.com/philipphenkel/threadpool) cannot pass testing, see [README](comparison/philipphenkel/README.md#warning).\u003cbr\u003e\r\nP.S. [tghosgor/threadpool11](https://github.com/tghosgor/threadpool11) cannot pass testing, see [README](comparison/tghosgor/README.md#warning).\u003cbr\u003e\r\nP.S. [mtrebi/thread-pool](https://github.com/mtrebi/thread-pool) cannot pass testing, see [README](comparison/mtrebi/README.md#warning).\u003cbr\u003e\r\nSee the [directory](comparison/) for more details.\r\n# Compiler\r\n\tVisual Studio 2017 15.5.5\r\n\tg++ 7.2.1\r\n\tclang++ 5.0.1\r\n# How to compile\r\nYou have to download [my lib](https://github.com/Fdhvdu/lib) first.\u003cbr\u003e\r\nThe directory should be look like\r\n\r\n\t├── lib\r\n\t│   ├── header\r\n\t│   ├── LICENSE\r\n\t│   ├── README.md\r\n\t│   ├── src\r\n\t│   └── tutorial\r\n\t└── ThreadPool\r\n\t    ├── comparison\r\n\t    ├── header\r\n\t    ├── LICENSE\r\n\t    ├── README.md\r\n\t    ├── src\r\n\t    └── tutorial\r\nDon't forget to compile lib/src/Scope_guard.cpp.\r\n# Compilation errors?\r\nSee [How to compile](https://github.com/Fdhvdu/ThreadPool/blob/master/README.md#how-to-compile) or email me\r\n# Tutorial\r\nI provide [example.cpp](tutorial/example.cpp) and [example_ret.cpp](tutorial/example_ret.cpp) to help you understand how to use this powerful thread pool\u003cbr\u003e\r\nTo use [example.cpp](tutorial/example.cpp):\u003cbr\u003e\r\n\r\n\tg++ -std=c++17 tutorial/example.cpp src/* ../lib/src/Scope_guard.cpp\r\nTo use [example_ret.cpp](tutorial/example_ret.cpp):\u003cbr\u003e\r\n\r\n\tg++ -std=c++17 tutorial/example_ret.cpp src/IThreadPoolItemBase.cpp ../lib/src/Scope_guard.cpp\r\n# Future work\r\nadd a non-block version of `CThreadPool::add`\u003cbr\u003e\r\nwork stealing\r\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFdhvdu%2FThreadPool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFdhvdu%2FThreadPool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFdhvdu%2FThreadPool/lists"}