{"id":15108653,"url":"https://github.com/dougbinks/enkits","last_synced_at":"2025-05-14T08:09:58.451Z","repository":{"id":27591919,"uuid":"31075078","full_name":"dougbinks/enkiTS","owner":"dougbinks","description":"A permissively licensed C and C++ Task Scheduler for creating parallel programs. Requires C++11 support.","archived":false,"fork":false,"pushed_at":"2025-01-27T18:44:47.000Z","size":718,"stargazers_count":1820,"open_issues_count":7,"forks_count":152,"subscribers_count":60,"default_branch":"master","last_synced_at":"2025-04-11T19:59:43.874Z","etag":null,"topics":["c","c-plus-plus","enkits","gamedev","multithreading","scheduling","thread"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"LineageOS/android_packages_apps_Settings","license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dougbinks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"License.txt","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,"zenodo":null},"funding":{"github":"dougbinks","patreon":"enkisoftware","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://www.enkisoftware.com/"}},"created_at":"2015-02-20T17:05:59.000Z","updated_at":"2025-04-11T12:43:15.000Z","dependencies_parsed_at":"2023-01-14T07:05:05.444Z","dependency_job_id":"35526c01-aa7e-49c3-b17c-2103a4a3d598","html_url":"https://github.com/dougbinks/enkiTS","commit_stats":{"total_commits":547,"total_committers":13,"mean_commits":42.07692307692308,"dds":"0.034734917733089565","last_synced_commit":"d824d306bc2bdf01486c1de74b44b037efb9f48a"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dougbinks%2FenkiTS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dougbinks%2FenkiTS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dougbinks%2FenkiTS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dougbinks%2FenkiTS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dougbinks","download_url":"https://codeload.github.com/dougbinks/enkiTS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101559,"owners_count":22014908,"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","c-plus-plus","enkits","gamedev","multithreading","scheduling","thread"],"created_at":"2024-09-25T22:20:54.457Z","updated_at":"2025-05-14T08:09:53.442Z","avatar_url":"https://github.com/dougbinks.png","language":"C++","readme":"Support development of enkiTS through [Github Sponsors](https://github.com/sponsors/dougbinks) or [Patreon](https://www.patreon.com/enkisoftware)\n\n[\u003cimg src=\"https://img.shields.io/static/v1?logo=github\u0026label=Github\u0026message=Sponsor\u0026color=#ea4aaa\" width=\"200\"/\u003e](https://github.com/sponsors/dougbinks)    [\u003cimg src=\"https://c5.patreon.com/external/logo/become_a_patron_button@2x.png\" alt=\"Become a Patron\" width=\"150\"/\u003e](https://www.patreon.com/enkisoftware)\n\n![enkiTS Logo](https://github.com/dougbinks/images/blob/master/enkiTS_logo_no_padding.png?raw=true)\n# enkiTS\n| [Master branch](https://github.com/dougbinks/enkiTS/) | [Dev branch](https://github.com/dougbinks/enkiTS/tree/dev) |\n| --- | --- |\n| [![Build Status for branch: master](https://github.com/dougbinks/enkiTS/actions/workflows/build.yml/badge.svg)](https://github.com/dougbinks/enkiTS/actions) | [![Build Status for branch: dev](https://github.com/dougbinks/enkiTS/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/dougbinks/enkiTS/actions) |\n\n## enki Task Scheduler\n\nA permissively licensed C and C++ Task Scheduler for creating parallel programs. Requires C++11 support.\n\nThe primary goal of enkiTS is to help developers create programs which handle both data and task level parallelism to utilize the full performance of multicore CPUs, whilst being lightweight (only a small amount of code) and easy to use.\n\n* [C++ API via src/TaskScheduler.h](src/TaskScheduler.h)\n* [C API via src/TaskScheduler_c.h](src/TaskScheduler_c.h)\n\nenkiTS was developed for, and is used in [enkisoftware](http://www.enkisoftware.com/)'s Avoyd codebase.\n\n## Platforms\n\n- Windows, Linux, Mac OS, Android (should work on iOS) \n- x64 \u0026 x86, ARM\n\nenkiTS is primarily developed on x64 and x86 Intel architectures on MS Windows, with well tested support for Linux and somewhat less frequently tested support on Mac OS and ARM Android.\n\n## Examples\n\nSeveral examples exist in  the [example folder](https://github.com/dougbinks/enkiTS/tree/master/example).\n\nFor further examples, see https://github.com/dougbinks/enkiTSExamples\n\n## Building\n\nBuilding enkiTS is simple, just add the files in enkiTS/src to your build system (_c.* files can be ignored if you only need C++ interface), and add enkiTS/src to your include path. Unix / Linux builds will likely require the pthreads library.\n\nFor C++\n\n  - Use `#include \"TaskScheduler.h\"`\n  - Add enkiTS/src to your include path\n  - Compile / Add to project: \n    - `TaskScheduler.cpp`\n  - Unix / Linux builds will likely require the pthreads library.\n\nFor C\n\n  - Use `#include \"TaskScheduler_c.h\"`\n  - Add enkiTS/src to your include path\n  - Compile / Add to project:\n    - `TaskScheduler.cpp`\n    - `TaskScheduler_c.cpp`\n  - Unix / Linux builds will likely require the pthreads library.\n\nFor cmake, on Windows / Mac OS X / Linux with cmake installed, open a prompt in the enkiTS directory and:\n\n1. `mkdir build`\n1. `cd build`\n1. `cmake ..`\n1. either run `make all` or for Visual Studio open `enkiTS.sln`\n\n## Project Features\n\n1. *Lightweight* - enkiTS is designed to be lean so you can use it anywhere easily, and understand it.\n1. *Fast, then scalable* - enkiTS is designed for consumer devices first, so performance on a low number of threads is important, followed by scalability.\n1. *Braided parallelism* - enkiTS can issue tasks from another task as well as from the thread which created the Task System, and has a simple task interface for both data parallel and task parallelism.\n1. *Up-front Allocation friendly* - enkiTS is designed for zero allocations during scheduling.\n1. *Can pin tasks to a given thread* - enkiTS can schedule a task which will only be run on the specified thread.\n1. *Can set task priorities* - Up to 5 task priorities can be configured via define ENKITS_TASK_PRIORITIES_NUM (defaults to 3). Higher priority tasks are run before lower priority ones.\n1. *Can register external threads to use with enkiTS* - Can configure enkiTS with numExternalTaskThreads which can be registered to use with the enkiTS API.\n1. *Custom allocator API* - can configure enkiTS with custom allocators, see [example/CustomAllocator.cpp](example/CustomAllocator.cpp) and [example/CustomAllocator_c.c](example/CustomAllocator_c.c).\n1. *Dependencies* - can set dependendencies between tasks see [example/Dependencies.cpp](example/Dependencies.cpp) and [example/Dependencies_c.c](example/Dependencies_c.c).\n1. *Completion Actions* - can perform an action on task completion. This avoids the expensive action of adding the task to the scheduler, and can be used to safely delete a completed task. See [example/CompletionAction.cpp](example/CompletionAction.cpp) and [example/CompletionAction_c.c](example/CompletionAction_c.c)\n1. **NEW** *Can wait for pinned tasks* - Can wait for pinned tasks, useful for creating IO threads which do no other work. See [example/WaitForNewPinnedTasks.cpp](example/WaitForNewPinnedTasks.cpp) and [example/WaitForNewPinnedTasks_c.c](example/WaitForNewPinnedTasks_c.c).\n\n## Installing\n\nI recommend using enkiTS directly from source in each project rather than installing it for system wide use. However enkiTS' cmake script can also be used to install the library\nif the `ENKITS_INSTALL` cmake variable is set to `ON` (it defaults to `OFF`).\n\nWhen installed the header files are installed in a subdirectory of the include path, `include/enkiTS` to ensure that they do not conflict with header files from other packages.\nWhen building applications either ensure this is part of the `INCLUDE_PATH` variable or ensure that enkiTS is in the header path in the source files, for example use `#include \"enkiTS/TaskScheduler.h\"` instead of `#include \"TaskScheduler.h\"`.\n\n## Using enkiTS\n\n### C++ usage\n- full example in [example/ParallelSum.cpp](example/ParallelSum.cpp)\n- C example in [example/ParallelSum_c.c](example/ParallelSum_c.c)\n```C\n#include \"TaskScheduler.h\"\n\nenki::TaskScheduler g_TS;\n\n// define a task set, can ignore range if we only do one thing\nstruct ParallelTaskSet : enki::ITaskSet {\n    void ExecuteRange(  enki::TaskSetPartition range_, uint32_t threadnum_ ) override {\n        // do something here, can issue tasks with g_TS\n    }\n};\n\nint main(int argc, const char * argv[]) {\n    g_TS.Initialize();\n    ParallelTaskSet task; // default constructor has a set size of 1\n    g_TS.AddTaskSetToPipe( \u0026task );\n\n    // wait for task set (running tasks if they exist)\n    // since we've just added it and it has no range we'll likely run it.\n    g_TS.WaitforTask( \u0026task );\n    return 0;\n}\n```\n\n### C++ 11 lambda usage\n- full example in [example/LambdaTask.cpp](example/LambdaTask.cpp)\n```C\n#include \"TaskScheduler.h\"\n\nenki::TaskScheduler g_TS;\n\nint main(int argc, const char * argv[]) {\n   g_TS.Initialize();\n\n   enki::TaskSet task( 1, []( enki::TaskSetPartition range_, uint32_t threadnum_  ) {\n         // do something here\n      }  );\n\n   g_TS.AddTaskSetToPipe( \u0026task );\n   g_TS.WaitforTask( \u0026task );\n   return 0;\n}\n```\n\n### Task priorities usage in C++\n- full example in [example/Priorities.cpp](example/Priorities.cpp)\n- C example in [example/Priorities_c.c](example/Priorities_c.c)\n```C\n// See full example in Priorities.cpp\n#include \"TaskScheduler.h\"\n\nenki::TaskScheduler g_TS;\n\nstruct ExampleTask : enki::ITaskSet\n{\n    ExampleTask( ) { m_SetSize = size_; }\n\n    void ExecuteRange(  enki::TaskSetPartition range_, uint32_t threadnum_ ) override {\n        // See full example in Priorities.cpp\n    }\n};\n\n\n// This example demonstrates how to run a long running task alongside tasks\n// which must complete as early as possible using priorities.\nint main(int argc, const char * argv[])\n{\n    g_TS.Initialize();\n\n    ExampleTask lowPriorityTask( 10 );\n    lowPriorityTask.m_Priority  = enki::TASK_PRIORITY_LOW;\n\n    ExampleTask highPriorityTask( 1 );\n    highPriorityTask.m_Priority = enki::TASK_PRIORITY_HIGH;\n\n    g_TS.AddTaskSetToPipe( \u0026lowPriorityTask );\n    for( int task = 0; task \u003c 10; ++task )\n    {\n        // run high priority tasks\n        g_TS.AddTaskSetToPipe( \u0026highPriorityTask );\n\n        // wait for task but only run tasks of the same priority or higher on this thread\n        g_TS.WaitforTask( \u0026highPriorityTask, highPriorityTask.m_Priority );\n    }\n    // wait for low priority task, run any tasks on this thread whilst waiting\n    g_TS.WaitforTask( \u0026lowPriorityTask );\n\n    return 0;\n}\n```\n\n### Pinned Tasks usage in C++\n- full example in [example/PinnedTask.cpp](example/PinnedTask.cpp)\n- C example in [example/PinnedTask_c.c](example/PinnedTask_c.c)\n```C\n#include \"TaskScheduler.h\"\n\nenki::TaskScheduler g_TS;\n\n// define a task set, can ignore range if we only do one thing\nstruct PinnedTask : enki::IPinnedTask {\n    void Execute() override {\n      // do something here, can issue tasks with g_TS\n    }\n};\n\nint main(int argc, const char * argv[]) {\n    g_TS.Initialize();\n    PinnedTask task; //default constructor sets thread for pinned task to 0 (main thread)\n    g_TS.AddPinnedTask( \u0026task );\n\n    // RunPinnedTasks must be called on main thread to run any pinned tasks for that thread.\n    // Tasking threads automatically do this in their task loop.\n    g_TS.RunPinnedTasks();\n\n    // wait for task set (running tasks if they exist)\n    // since we've just added it and it has no range we'll likely run it.\n    g_TS.WaitforTask( \u0026task );\n    return 0;\n}\n```\n\n### Dependency usage in C++\n- full example in [example/Dependencies.cpp](example/Dependencies.cpp)\n- C example in [example/Dependencies_c.c](example/Dependencies_c.c)\n```C\n#include \"TaskScheduler.h\"\n\nenki::TaskScheduler g_TS;\n\n// define a task set, can ignore range if we only do one thing\nstruct TaskA : enki::ITaskSet {\n    void ExecuteRange(  enki::TaskSetPartition range_, uint32_t threadnum_ ) override {\n        // do something here, can issue tasks with g_TS\n    }\n};\n\nstruct TaskB : enki::ITaskSet {\n    enki::Dependency m_Dependency;\n    void ExecuteRange(  enki::TaskSetPartition range_, uint32_t threadnum_ ) override {\n        // do something here, can issue tasks with g_TS\n    }\n};\n\nint main(int argc, const char * argv[]) {\n    g_TS.Initialize();\n    \n    // set dependencies once (can set more than one if needed).\n    TaskA taskA;\n    TaskB taskB;\n    taskB.SetDependency( taskB.m_Dependency, \u0026taskA );\n\n    g_TS.AddTaskSetToPipe( \u0026taskA ); // add first task\n    g_TS.WaitforTask( \u0026taskB );      // wait for last\n    return 0;\n}\n```\n\n### External task thread usage in C++\n- full example in [example/ExternalTaskThread.cpp](example/ExternalTaskThread.cpp)\n- C example in [example/ExternalTaskThread_c.c](example/ExternalTaskThread_c.c)\n```C\n#include \"TaskScheduler.h\"\n\nenki::TaskScheduler g_TS;\nstruct ParallelTaskSet : ITaskSet\n{\n    void ExecuteRange(  enki::TaskSetPartition range_, uint32_t threadnum_ ) override {\n        // Do something\n    }\n};\n\nvoid threadFunction()\n{\n    g_TS.RegisterExternalTaskThread();\n\n    // sleep for a while instead of doing something such as file IO\n    std::this_thread::sleep_for( std::chrono::milliseconds( num_ * 100 ) );\n\n    ParallelTaskSet task;\n    g_TS.AddTaskSetToPipe( \u0026task );\n    g_TS.WaitforTask( \u0026task);\n\n    g_TS.DeRegisterExternalTaskThread();\n}\n\nint main(int argc, const char * argv[])\n{\n    enki::TaskSchedulerConfig config;\n    config.numExternalTaskThreads = 1; // we have one extra external thread\n\n    g_TS.Initialize( config );\n\n    std::thread exampleThread( threadFunction );\n\n    exampleThread.join();\n\n    return 0;\n}\n```\n\n### WaitForPinnedTasks thread usage in C++ (useful for IO threads)\n- full example in [example/WaitForNewPinnedTasks.cpp](example/WaitForNewPinnedTasks.cpp)\n- C example in [example/WaitForNewPinnedTasks_c.c](example/WaitForNewPinnedTasks_c.c)\n```C++\n#include \"TaskScheduler.h\"\n\nenki::TaskScheduler g_TS;\n\nstruct RunPinnedTaskLoopTask : enki::IPinnedTask\n{\n    void Execute() override\n    {\n        while( !g_TS.GetIsShutdownRequested() )\n        {\n            g_TS.WaitForNewPinnedTasks(); // this thread will 'sleep' until there are new pinned tasks\n            g_TS.RunPinnedTasks();\n        }\n    }\n};\n\nstruct PretendDoFileIO : enki::IPinnedTask\n{\n    void Execute() override\n    {\n        // Do file IO\n    }\n};\n\nint main(int argc, const char * argv[])\n{\n    enki::TaskSchedulerConfig config;\n\n    // In this example we create more threads than the hardware can run,\n    // because the IO thread will spend most of it's time idle or blocked\n    // and therefore not scheduled for CPU time by the OS\n    config.numTaskThreadsToCreate += 1;\n\n    g_TS.Initialize( config );\n\n    // in this example we place our IO threads at the end\n    RunPinnedTaskLoopTask runPinnedTaskLoopTasks;\n    runPinnedTaskLoopTasks.threadNum = g_TS.GetNumTaskThreads() - 1;\n    g_TS.AddPinnedTask( \u0026runPinnedTaskLoopTasks );\n\n    // Send pretend file IO task to external thread FILE_IO\n    PretendDoFileIO pretendDoFileIO;\n    pretendDoFileIO.threadNum = runPinnedTaskLoopTasks.threadNum;\n    g_TS.AddPinnedTask( \u0026pretendDoFileIO );\n\n    // ensure runPinnedTaskLoopTasks complete by explicitly calling shutdown\n    g_TS.WaitforAllAndShutdown();\n\n    return 0;\n}\n```\n\n\n## Bindings\n\n- Odin [enkiTS Odin bindings](https://github.com/nadako/odin-enkiTS) by @nadako\n\n## Deprecated\n\n[The C++98 compatible branch](https://github.com/dougbinks/enkiTS/tree/C++98) has been deprecated as I'm not aware of anyone needing it.\n\nThe user thread versions are no longer being maintained as they are no longer in use. Similar functionality can be obtained with the externalTaskThreads\n* [User thread version  on Branch UserThread](https://github.com/dougbinks/enkiTS/tree/UserThread) for running enkiTS on other tasking / threading systems, so it can be used as in other engines as well as standalone for example.\n* [C++ 11 version of user threads on Branch UserThread_C++11](https://github.com/dougbinks/enkiTS/tree/UserThread_C++11)\n\n## Projects using enkiTS\n\n### [Avoyd](https://www.avoyd.com)\nAvoyd is an abstract 6 degrees of freedom voxel game. enkiTS was developed for use in our [in-house engine powering Avoyd](https://www.enkisoftware.com/faq#engine). \n\n![Avoyd screenshot](https://github.com/juliettef/Media/blob/main/Avoyd_2019-06-22_enkiTS_microprofile.jpg?raw=true)\n\n### [Imogen](https://github.com/CedricGuillemet/Imogen)\nGPU/CPU Texture Generator\n\n![Imogen screenshot](https://camo.githubusercontent.com/28347bc0c1627aa4f289e1b2b769afcb3a5de370/68747470733a2f2f692e696d6775722e636f6d2f7351664f3542722e706e67)\n\n### [ToyPathRacer](https://github.com/aras-p/ToyPathTracer)\nAras Pranckevičius' code for his series on [Daily Path Tracer experiments with various languages](https://aras-p.info/blog/2018/03/28/Daily-Pathtracer-Part-0-Intro/).\n\n![ToyPathTracer screenshot](https://github.com/aras-p/ToyPathTracer/blob/main/Shots/screenshot.jpg?raw=true).\n\n### [Mastering Graphics Programming with Vulkan](https://github.com/PacktPublishing/Mastering-Graphics-Programming-with-Vulkan)\nMarco Castorina and Gabriel Sassone's book on developing a modern rendering engine from first principles using the Vulkan API. enkiTS is used as the task library to distribute work across cores.\n\n![Mastering Graphics Programming with Vulkan](https://static.packt-cdn.com/products/9781803244792/cover/smaller)\n\n## License (zlib)\n\nCopyright (c) 2013-2020 Doug Binks\n\nThis software is provided 'as-is', without any express or implied\nwarranty. In no event will the authors be held liable for any damages\narising from the use of this software.\n\nPermission is granted to anyone to use this software for any purpose,\nincluding commercial applications, and to alter it and redistribute it\nfreely, subject to the following restrictions:\n\n1. The origin of this software must not be misrepresented; you must not\n   claim that you wrote the original software. If you use this software\n   in a product, an acknowledgement in the product documentation would be\n   appreciated but is not required.\n2. Altered source versions must be plainly marked as such, and must not be\n   misrepresented as being the original software.\n3. This notice may not be removed or altered from any source distribution.\n","funding_links":["https://github.com/sponsors/dougbinks","https://patreon.com/enkisoftware","https://www.enkisoftware.com/","https://www.patreon.com/enkisoftware"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdougbinks%2Fenkits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdougbinks%2Fenkits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdougbinks%2Fenkits/lists"}