https://github.com/sagiegurari/c_thread_pool
Thread Pool for C
https://github.com/sagiegurari/c_thread_pool
c thread thread-pool threading
Last synced: 11 months ago
JSON representation
Thread Pool for C
- Host: GitHub
- URL: https://github.com/sagiegurari/c_thread_pool
- Owner: sagiegurari
- License: apache-2.0
- Created: 2023-04-18T16:53:58.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T07:12:31.000Z (almost 3 years ago)
- Last Synced: 2025-06-03T02:12:33.443Z (about 1 year ago)
- Topics: c, thread, thread-pool, threading
- Language: C
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Thread Pool
[](https://github.com/sagiegurari/c_thread_pool/actions)
[](https://github.com/sagiegurari/c_thread_pool/releases)
[](https://github.com/sagiegurari/c_thread_pool/blob/master/LICENSE)
> Thread Pool for C.
* [Overview](#overview)
* [Usage](#usage)
* [Contributing](.github/CONTRIBUTING.md)
* [Release History](CHANGELOG.md)
* [License](#license)
## Overview
This library provides a simple thread pool and enables running functions in the background.
```c
#include "threadpool.h"
#include
#include
static void do_in_background(void *);
int main()
{
printf("Library Examples:\n");
struct ThreadPool *pool = threadpool_new();
int loops = 100;
int parallel = 100;
for (int loop = 0; loop < loops; loop++)
{
for (int index = 0; index < parallel; index++)
{
char *args = (char *)malloc(sizeof(char) * 100);
sprintf(args, "loop: %d sub loop: %d", loop, index);
// invoke function in the background
threadpool_invoke(pool, do_in_background, args);
}
// block until all threads finished processing all requests
threadpool_block(pool);
}
// Once done, release the pool.
// This will block until all threads are done.
threadpool_release(pool);
return(0);
}
static void do_in_background(void *args)
{
printf("In thread, args: %s\n", (char *)args);
}
```
## Contributing
See [contributing guide](.github/CONTRIBUTING.md)
See [Changelog](CHANGELOG.md)
## License
Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.