{"id":15049522,"url":"https://github.com/taymindis/atomic_threadpool","last_synced_at":"2025-04-10T02:13:35.745Z","repository":{"id":57723518,"uuid":"146233810","full_name":"Taymindis/atomic_threadpool","owner":"Taymindis","description":"it's a smallest library that provides a lock-free thread pool sharing on multithreading, it design for scalability","archived":false,"fork":false,"pushed_at":"2018-09-15T14:03:44.000Z","size":294,"stargazers_count":28,"open_issues_count":1,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T02:13:04.908Z","etag":null,"topics":["asynchronous","atomic-design","c","cross-platform","java","jni","lockfree","multithreading","threadpool"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Taymindis.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":"2018-08-27T01:53:58.000Z","updated_at":"2025-03-30T00:06:09.000Z","dependencies_parsed_at":"2022-08-28T14:01:06.190Z","dependency_job_id":null,"html_url":"https://github.com/Taymindis/atomic_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/Taymindis%2Fatomic_threadpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Fatomic_threadpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Fatomic_threadpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Fatomic_threadpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Taymindis","download_url":"https://codeload.github.com/Taymindis/atomic_threadpool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142902,"owners_count":21054671,"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":["asynchronous","atomic-design","c","cross-platform","java","jni","lockfree","multithreading","threadpool"],"created_at":"2024-09-24T21:21:07.075Z","updated_at":"2025-04-10T02:13:35.716Z","avatar_url":"https://github.com/Taymindis.png","language":"C","readme":"# atomic_threadpool\nit is c/c++ library, it's a smallest library that provides a lock-free thread pool sharing on multithreading, it design for scalability\n\n\n## For Linux OS build\n\n## Installation\n\n```bash\nmkdir build\n\ncd build\n\ncmake ..\n\nmake\n\nsudo make install\n\n```\n\n\n\n## Uninstallation\n\n```bash\ncd build\n\nsudo make uninstall\n\n```\n\n\n## Example to run\n```c\n\n#include \u003cstdio.h\u003e\n#include \u003cpthread.h\u003e\n#include \"at_thpool.h\"\n\n\n#define TASK_SIZE 200\n\nvoid t1(void *arg);\nvoid t2(void *arg);\nvoid t3(void *arg);\nvoid t4(void *arg);\n\nvoid t1(void *arg) {\n\tprintf(\"t1 is running on thread #%u \\n\", (int)pthread_self());\n}\n\nvoid t2(void *arg) {\n\tprintf(\"t2 is running on thread #%u\\n\", (int)pthread_self());\n}\n\nvoid t3(void *arg) {\n\tprintf(\"t3 is running on thread #%u\\n\", (int)pthread_self());\n}\n\nvoid t4(void *arg) {\n\tprintf(\"t4 is running on thread #%u\\n\", (int)pthread_self());\n}\n\nint main(void) {\n\tint nthreads = 8;//sysconf(_SC_NPROCESSORS_ONLN); // Linux\n\n\tprintf(\"Share thread pool with %d threads with at lease totalthroughput * nthreads task size\\n\", nthreads);\n\tat_thpool_t *thpool = at_thpool_create(nthreads);\n\n\tprintf(\"assigned %d tasks between %d threads\\n\", TASK_SIZE, nthreads);\n\tint i;\n\tfor (i = 0; i \u003c TASK_SIZE; i++) {\n\t\tat_thpool_newtask(thpool, t1, NULL);\n\t\tat_thpool_newtask(thpool, t2, NULL);\n\t\tat_thpool_newtask(thpool, t3, NULL);\n\t\tat_thpool_newtask(thpool, t4, NULL);\n\t}\n\n#if defined _WIN32 || _WIN64\n\tSleep(1000);\n#else\n\tusleep(1000 * 1000);\n#endif\n\n\tputs(\"shutdown thread pool\");\n\tat_thpool_gracefully_shutdown(thpool);\n\n\treturn 0;\n}\n\n```\n\n\n### How to wait for task to finish on main thread\n\nAtomicThreadPool design for lock free, it does not wait for anyone, to wait for specified task to finished, client should pass the value to indicate it has done.\n\nFor Example for wait task: \n\n```c\n\n#include \u003cstdio.h\u003e\n#include \u003cpthread.h\u003e\n#include \"at_thpool.h\"\n\ntypedef struct myagent_s {\n\tint has_task_done;\n\tvoid *my_value;\n} my_agent;\n\nvoid t1(void *arg);\n\nvoid t1(void *arg) {\n\tmy_agent *agent = (my_agent*) arg;\n\n\tprintf(\"t1 is running on thread #%u \\n\", (int)pthread_self());\n\n\t/** Doing heavy task **/\n\n\tagent-\u003ehas_task_done = 1;\n\n}\n\nint main(void) {\n\tint nthreads = 8;//sysconf(_SC_NPROCESSORS_ONLN); // Linux\n\n\tprintf(\"Share thread pool with %d threads with at lease totalthroughput * nthreads task size\\n\", nthreads);\n\tat_thpool_t *thpool = at_thpool_create(nthreads);\n\n\tint i;\n\tmy_agent agent;\n\tagent.has_task_done = 0\n\n\tat_thpool_newtask(thpool, t1, \u0026agent);\nwhile (!agent.has_task_done) {\n#if defined _WIN32 || _WIN64\n\tSleep(1);\n#else\n\tusleep(1000);\n#endif\n}\n\n\tputs(\"shutdown thread pool\");\n\tat_thpool_gracefully_shutdown(thpool);\n\n\treturn 0;\n}\n\n\n```\n\n\n## For manual build\ngcc -std=c11 -I./ -Ilfqueue/ at_thpool.c lfqueue/lfqueue.c threadpool_example.c -pthread\n\n\n## for Windows os build\n\n### Recommend to use VS2017 to build\n\n#### include the sources file at_thpool.c at_thpool.h lfqueue.c lfqueue.h into VS2017 project solution.\n\nAlternatively, \n\n#### Download the Dev-C++ IDE - https://sourceforge.net/projects/orwelldevcpp/\n\n\n\n#### You can use any IDE/build tools as you wish, just include the source files to your project\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaymindis%2Fatomic_threadpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaymindis%2Fatomic_threadpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaymindis%2Fatomic_threadpool/lists"}