{"id":26400060,"url":"https://github.com/diharaw/dwThreadPool","last_synced_at":"2025-03-17T14:01:15.354Z","repository":{"id":106830575,"uuid":"74936215","full_name":"diharaw/dw-thread-pool","owner":"diharaw","description":"A simple, header-only, dependency-free, C++ 11 based ThreadPool library.","archived":false,"fork":false,"pushed_at":"2020-06-03T01:39:06.000Z","size":281,"stargazers_count":33,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T00:02:04.347Z","etag":null,"topics":["jobsystem","task-scheduler","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/diharaw.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":"2016-11-28T04:09:36.000Z","updated_at":"2024-10-15T10:06:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"640aa88a-083a-40cc-b296-33aacc463003","html_url":"https://github.com/diharaw/dw-thread-pool","commit_stats":null,"previous_names":["diharaw/dwthreadpool"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diharaw%2Fdw-thread-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diharaw%2Fdw-thread-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diharaw%2Fdw-thread-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diharaw%2Fdw-thread-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diharaw","download_url":"https://codeload.github.com/diharaw/dw-thread-pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244047608,"owners_count":20389205,"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":["jobsystem","task-scheduler","thread-pool"],"created_at":"2025-03-17T14:00:34.865Z","updated_at":"2025-03-17T14:01:15.329Z","avatar_url":"https://github.com/diharaw.png","language":"C++","readme":"[![License: MIT](https://img.shields.io/packagist/l/doctrine/orm.svg)](https://opensource.org/licenses/MIT)\n\n# dwThreadPool\nA simple, header-only, dependency-free, C++ 11 based ThreadPool library.\n\n## Features\n\n* C++ 11\n* Minimal Source Code\n* Header-only\n* No external dependencies\n* Task Grouping/Child Tasks\n* Task Continuations\n* No dynamic allocations for the user\n* Fully cross-platform\n\n## Compilers\n* MSVC\n* AppleClang\n\n## Basics\n\n```cpp\n#include \u003cthread_pool.hpp\u003e\n\n// create simple struct containing task data.\nstruct my_task_data\n{\n\t  int   foo;\n\t  float bar;\n}\n\n// task functions have to conform to this signature. can be free functions or methods.\nvoid my_task(void* args)\n{\n\t// do work here...\n}\n\nint main() \n{\n\t// create thread pool instance. \n    \n    \t// Default constructor creates (N-1) number of workers, with N being the number of hardware threads.\n    \tdw::ThreadPool thread_pool;\n    \n    \t// Allocate a new task from the thread pool. No dynamic allocations are done internally\n    \tdw::Task* task = thread_pool.allocate();\n  \n    \t// Bind task function.\n    \ttask-\u003efunction = my_task;\n    \n    \t// Useful template function for casting task data to a pointer of your custom task data struct.\n    \tmy_task_data* data = dw::task_data\u003cmy_task_data\u003e(task);\n    \n    \t// Fill in task data.\n    \tdata-\u003efoo = 1;\n    \tdata-\u003ebar = 2.0f;\n    \n    \t// enqueue task into thread pool.\n    \tthread_pool.enqueue(task);\n    \n    \t// wait till work is done.\n    \tthread_pool.wait_for_all();\n    \n    \treturn 0;\n}\n```\n\n## Waiting for a specified Task\n\n```cpp\ndw::Task* task = thread_pool.allocate();\n\nthread_pool.enqueue(task);\n\n// Busy waits on the calling thread until the specified function is done.\nthread_pool.wait_for_one(task);\n\n```\n\n## Check whether a specified Task is done\n\n```cpp\ndw::Task* task = thread_pool.allocate();\n\nthread_pool.enqueue(task);\n\n// Returns true is task is done, false if not.\nthread_pool.is_done(task);\n\n```\n\n## Task Continuations\n\n```cpp\ndw::Task* task1 = thread_pool.allocate();\ndw::Task* task2 = thread_pool.allocate();\n\n// Bind data and functions...\n\n// First, add task2 as a continuation of task1.\nthread_pool.add_as_continuation(task1, task2);\n\n// Then enqueue the first task into the thread pool. The second task will automatically run.\nthread_pool.enqueue(task1);\n\n```\n\n## Task Grouping/Child Tasks\nNOTE: Child Tasks here refer to grouping a set of tasks to finish together. It is not meant to express dependencies between tasks. For that, use Task Continuations.\n\n```cpp\ndw::Task* parent_task;\ndw::Task* child_tasks[10];\n\n// Allocate and bind parent task.\nparent_task = thread_pool.allocate();\n\nfor(uint32_t i = 0; i \u003c 10; i++)\n{\n\t// Allocate and bind Child tasks.\n\tchild_tasks[i] = tp.allocate();\n\n\t// Add child as children of the parent task.\n\tthread_pool.add_as_child(parent_task, child_tasks[i]);\n\n    \t// Immediately enqueue each child task.\n\tthread_pool.enqueue(child_tasks[i]);\n}\n\n// Lastly enqueue parent task\nthread_pool.enqueue(parent_task);\n\n// Wait on the parent task to ensure the entire task group is completed\nthread_pool.wait_for_one(parent_task);\n\n```\n\n## Remotery Screenshot of Example\n\n![alt text](https://github.com/diharaw/dwThreadPool/raw/master/doc/screenshot.png \"Remotery Screenshot\")\n\n## Building the Example\n\nThe example project can be built using the [CMake](https://cmake.org/) build system generator. Plenty of tutorials around for that.\n\n## License\n```\nCopyright (c) 2019 Dihara Wijetunga\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and \nassociated documentation files (the \"Software\"), to deal in the Software without restriction, \nincluding without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,\nand/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, \nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial\nportions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT \nLIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. \nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE \nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiharaw%2FdwThreadPool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiharaw%2FdwThreadPool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiharaw%2FdwThreadPool/lists"}