From ebe78873c0adc00e13e96dd96820b6d2b4e3f109 Mon Sep 17 00:00:00 2001 From: shaun Date: Sat, 30 Dec 2017 01:26:31 -0500 Subject: [PATCH 01/43] Update example.c without the wait the 40 tasks will not have time to complete --- example.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/example.c b/example.c index 0ac638f..e53d280 100644 --- a/example.c +++ b/example.c @@ -13,16 +13,11 @@ #include #include +#include #include "thpool.h" - -void task1(){ - printf("Thread #%u working on task1\n", (int)pthread_self()); -} - - -void task2(){ - printf("Thread #%u working on task2\n", (int)pthread_self()); +void task(void *arg){ + printf("Thread #%u working on %d\n", (int)pthread_self(), (int) arg); } @@ -33,11 +28,11 @@ int main(){ puts("Adding 40 tasks to threadpool"); int i; - for (i=0; i<20; i++){ - thpool_add_work(thpool, (void*)task1, NULL); - thpool_add_work(thpool, (void*)task2, NULL); + for (i=0; i<40; i++){ + thpool_add_work(thpool, (void*)task, (void*)(uintptr_t)i); }; + thpool_wait(thpool); puts("Killing threadpool"); thpool_destroy(thpool); From f0d75f72eb19cf17fedc437f682ac9baf5fad320 Mon Sep 17 00:00:00 2001 From: andamiro Date: Fri, 30 Nov 2018 17:15:58 +0900 Subject: [PATCH 02/43] thpool.c:458 ~ 464 modify Remark Message --- thpool.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/thpool.c b/thpool.c index f5696f0..cfec0cc 100644 --- a/thpool.c +++ b/thpool.c @@ -456,11 +456,7 @@ static void jobqueue_push(jobqueue* jobqueue_p, struct job* newjob){ /* Get first job from queue(removes it from queue) -<<<<<<< HEAD - * * Notice: Caller MUST hold a mutex -======= ->>>>>>> da2c0fe45e43ce0937f272c8cd2704bdc0afb490 */ static struct job* jobqueue_pull(jobqueue* jobqueue_p){ From 35a6d7427b50831a76a6cdc3f354396a311f3e18 Mon Sep 17 00:00:00 2001 From: Erik Janssen Date: Thu, 6 Dec 2018 21:35:50 +0100 Subject: [PATCH 03/43] Fixed wrong check for malloc result, as found with cppcheck --- thpool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thpool.c b/thpool.c index f5696f0..065182c 100644 --- a/thpool.c +++ b/thpool.c @@ -282,7 +282,7 @@ int thpool_num_threads_working(thpool_* thpool_p){ static int thread_init (thpool_* thpool_p, struct thread** thread_p, int id){ *thread_p = (struct thread*)malloc(sizeof(struct thread)); - if (thread_p == NULL){ + if (*thread_p == NULL){ err("thread_init(): Could not allocate memory for thread\n"); return -1; } From 71f5bc961318e7040a4febc969875e36d377b249 Mon Sep 17 00:00:00 2001 From: RhythmLian <916822670@qq.com> Date: Fri, 22 Nov 2019 08:23:27 +0800 Subject: [PATCH 04/43] Fix warning at line 285. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It may can’t catch the malloc error. --- thpool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thpool.c b/thpool.c index f5696f0..065182c 100644 --- a/thpool.c +++ b/thpool.c @@ -282,7 +282,7 @@ int thpool_num_threads_working(thpool_* thpool_p){ static int thread_init (thpool_* thpool_p, struct thread** thread_p, int id){ *thread_p = (struct thread*)malloc(sizeof(struct thread)); - if (thread_p == NULL){ + if (*thread_p == NULL){ err("thread_init(): Could not allocate memory for thread\n"); return -1; } From 12656655c7b803e8e4b44f0cafa436967dae2a9d Mon Sep 17 00:00:00 2001 From: Aneesh Joshi Date: Mon, 16 Dec 2019 14:52:37 -0500 Subject: [PATCH 05/43] fix typo: `untill` -> `until` --- thpool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thpool.h b/thpool.h index 04d5af2..1caee8e 100644 --- a/thpool.h +++ b/thpool.h @@ -20,7 +20,7 @@ typedef struct thpool_* threadpool; /** * @brief Initialize threadpool * - * Initializes a threadpool. This function will not return untill all + * Initializes a threadpool. This function will not return until all * threads have initialized successfully. * * @example @@ -77,7 +77,7 @@ int thpool_add_work(threadpool, void (*function_p)(void*), void* arg_p); * Smart polling is used in wait. The polling is initially 0 - meaning that * there is virtually no polling at all. If after 1 seconds the threads * haven't finished, the polling interval starts growing exponentially - * untill it reaches max_secs seconds. Then it jumps down to a maximum polling + * until it reaches max_secs seconds. Then it jumps down to a maximum polling * interval assuming that heavy processing is being used in the threadpool. * * @example From fe540f09b9149fb88ff325548baa42e11ea2b43b Mon Sep 17 00:00:00 2001 From: Gonzalo Diethelm Date: Mon, 20 Jul 2020 18:00:26 +0200 Subject: [PATCH 06/43] Cleaned up design doc --- docs/Design.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/Design.md b/docs/Design.md index 68450ad..c45394b 100644 --- a/docs/Design.md +++ b/docs/Design.md @@ -1,47 +1,47 @@ ## High level - + Description: Library providing a threading pool where you can add work on the fly. The number of threads in the pool is adjustable when creating the pool. In most cases this should equal the number of threads supported by your cpu. - + For an example on how to use the threadpool, check the main.c file or just read the documentation found in the README.md file. - + In this header file a detailed overview of the functions and the threadpool's logical - scheme is presented in case you wish to tweak or alter something. - - - - _______________________________________________________ + scheme is presented in case you wish to tweak or alter something. + + + + _______________________________________________________ / \ - | JOB QUEUE | job1 | job2 | job3 | job4 | .. | + | JOB QUEUE | job1 | job2 | job3 | job4 | .. | | | | threadpool | thread1 | thread2 | .. | \_______________________________________________________/ - - + + Description: Jobs are added to the job queue. Once a thread in the pool - is idle, it is assigned with the first job from the queue(and - erased from the queue). It's each thread's job to read from - the queue serially(using lock) and executing each job + is idle, it is assigned the first job from the queue (and that job is + erased from the queue). It is each thread's job to read from + the queue serially (using lock) and executing each job until the queue is empty. - - + + Scheme: - - thpool______ jobqueue____ ______ + + thpool______ jobqueue____ ______ | | | | .----------->|_job0_| Newly added job | | | rear ----------' |_job1_| | jobqueue----------------->| | |_job2_| - | | | front ----------. |__..__| + | | | front ----------. |__..__| |___________| |___________| '----------->|_jobn_| Job for thread to take - - - job0________ + + + job0________ | | | function----> | | | arg-------> - | | job1________ + | | job1________ | next-------------->| | |___________| | |.. From 06d4b0411b2099cb6a302766c232e54eb2ceee33 Mon Sep 17 00:00:00 2001 From: Gonzalo Diethelm Date: Mon, 20 Jul 2020 18:02:06 +0200 Subject: [PATCH 07/43] Cleaned up FAQ doc --- docs/FAQ.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index a82c3f0..0af0589 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -1,7 +1,7 @@ +### Why isn't `pthread_exit()` used to exit a thread? -###Why isn't pthread_exit() used to exit a thread? -`thread_do` used to use pthread_exit(). However that resulted in -hard times of testing for memory leaks. The reason is that on pthread_exit() +`thread_do` used to use `pthread_exit()`. However that resulted in +hard times of testing for memory leaks. The reason is that on `pthread_exit()` not all memory is freed bt pthread (probably for future threads or false belief that the application is terminating). For these reasons a simple return is used. @@ -9,27 +9,28 @@ is used. Interestingly using `pthread_exit()` results in much more memory being allocated. -###Why do you use sleep() after calling thpool_destroy()? -This is needed only in the tests. The reason is that if you call thpool_destroy -and then exit immedietely, maybe the program will exit before all the threads +### Why do you use `sleep()` after calling `thpool_destroy()`? + +This is needed only in the tests. The reason is that if you call `thpool_destroy()` +and then exit immediately, maybe the program will exit before all the threads had the time to deallocate. In that way it is impossible to check for memory leaks. -In production you don't have to worry about this since if you call exit, -immedietely after you destroyied the pool, the threads will be freed -anyway by the OS. If you eitherway destroy the pool in the middle of your +In production you don't have to worry about this since if you call `exit()`, +immediately after you destroyed the pool, the threads will be freed +anyway by the OS. If you anyway destroy the pool in the middle of your program it doesn't matter again since the program will not exit immediately and thus threads will have more than enough time to terminate. +### Why does `wait()` use all my CPU? -###Why does wait() use all my CPU? -Notice: As of 11-Dec-2015 wait() doesn't use polling anymore. Instead a conditional variable is being used so in theory there should not be any CPU overhead. +Notice: As of 11-Dec-2015 `wait()` doesn't use polling anymore. Instead a conditional variable is being used so in theory there should not be any CPU overhead. Normally `wait()` will spike CPU usage to full when called. This is normal as long as it doesn't last for more than 1 second. The reason this happens is that `wait()` goes through various phases of polling (what is called smart polling). * Initially there is no interval between polling and hence the 100% use of your CPU. * After that the polling interval grows exponentially. * Finally after x seconds, if there is still work, polling falls back to a very big interval. - + The reason `wait()` works in this way, is that the function is mostly used when someone wants to wait for some calculation to finish. So if the calculation is assumed to take a long time then we don't want to poll too often. Still we want to poll fast in case the calculation is a simple one. To solve these two problems, this seemingly awkward behaviour is present. From 0012ce22b9873f6721217dd491fb555289822eaa Mon Sep 17 00:00:00 2001 From: Gonzalo Diethelm Date: Mon, 20 Jul 2020 18:03:48 +0200 Subject: [PATCH 08/43] Fix casting of function pointers Found via -Wpedantic --- example.c | 4 ++-- thpool.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example.c b/example.c index 0ac638f..ba60ade 100644 --- a/example.c +++ b/example.c @@ -34,8 +34,8 @@ int main(){ puts("Adding 40 tasks to threadpool"); int i; for (i=0; i<20; i++){ - thpool_add_work(thpool, (void*)task1, NULL); - thpool_add_work(thpool, (void*)task2, NULL); + thpool_add_work(thpool, task1, NULL); + thpool_add_work(thpool, task2, NULL); }; puts("Killing threadpool"); diff --git a/thpool.c b/thpool.c index bc3a789..dcb5858 100644 --- a/thpool.c +++ b/thpool.c @@ -290,7 +290,7 @@ static int thread_init (thpool_* thpool_p, struct thread** thread_p, int id){ (*thread_p)->thpool_p = thpool_p; (*thread_p)->id = id; - pthread_create(&(*thread_p)->pthread, NULL, (void *)thread_do, (*thread_p)); + pthread_create(&(*thread_p)->pthread, NULL, (void * (*)(void *)) thread_do, (*thread_p)); pthread_detach((*thread_p)->pthread); return 0; } From 2a549a6613ceece79732eee20768ad77b6ef3834 Mon Sep 17 00:00:00 2001 From: Manos Date: Mon, 20 Jul 2020 17:31:40 +0100 Subject: [PATCH 09/43] Add .circleci/config.yml --- .circleci/config.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..01c267c --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,13 @@ +# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference +version: 2.1 +# Use a package of configuration called an orb. +orbs: + # Declare a dependency on the welcome-orb + welcome: circleci/welcome-orb@0.4.1 +# Orchestrate or schedule a set of jobs +workflows: + # Name the workflow "welcome" + welcome: + # Run the welcome/run job in its own container + jobs: + - welcome/run \ No newline at end of file From 3da0ca585ebb8d1180f6a1066df55fbe3d77cfbc Mon Sep 17 00:00:00 2001 From: "Manos S.H" Date: Mon, 20 Jul 2020 19:54:18 +0100 Subject: [PATCH 10/43] Update circleci config --- .circleci/config.yml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 01c267c..786ede6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,13 +1,19 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference version: 2.1 -# Use a package of configuration called an orb. -orbs: - # Declare a dependency on the welcome-orb - welcome: circleci/welcome-orb@0.4.1 -# Orchestrate or schedule a set of jobs + +jobs: + test: + docker: + - image: gcc:9.2 + steps: + - checkout + - run: + name: Test + command: | + cd tests/ + ./normal_compile.sh + ./optimized_compile.sh + workflows: - # Name the workflow "welcome" - welcome: - # Run the welcome/run job in its own container + test: jobs: - - welcome/run \ No newline at end of file + - test From b0d528d7ae07074eccad3a01fbfcbd80aa0e59de Mon Sep 17 00:00:00 2001 From: "Manos S.H" Date: Mon, 20 Jul 2020 20:31:32 +0100 Subject: [PATCH 11/43] Run tests in custom docker container --- .circleci/Dockerfile | 4 ++++ .circleci/README.md | 4 ++++ .circleci/config.yml | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .circleci/Dockerfile create mode 100644 .circleci/README.md diff --git a/.circleci/Dockerfile b/.circleci/Dockerfile new file mode 100644 index 0000000..5b3193c --- /dev/null +++ b/.circleci/Dockerfile @@ -0,0 +1,4 @@ +FROM ubuntu + +RUN apt-get update && \ + apt-get -y install gcc valgrind time python diff --git a/.circleci/README.md b/.circleci/README.md new file mode 100644 index 0000000..fa77c85 --- /dev/null +++ b/.circleci/README.md @@ -0,0 +1,4 @@ +Build and push container + + docker build -t pithikos/test-c-thread-pool . + docker push pithikos/test-c-thread-pool diff --git a/.circleci/config.yml b/.circleci/config.yml index 786ede6..26df327 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2.1 jobs: test: docker: - - image: gcc:9.2 + - image: pithikos/test-c-thread-pool steps: - checkout - run: From c0f8973cf62d5faca9c412d72c0af81c1766f201 Mon Sep 17 00:00:00 2001 From: "Manos S.H" Date: Mon, 20 Jul 2020 20:39:49 +0100 Subject: [PATCH 12/43] Update badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 694a56a..1240bf7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Build status](http://178.62.170.124:3000/pithikos/c-thread-pool/badge/?branch=master) +[![CircleCI](https://circleci.com/gh/Pithikos/C-Thread-Pool.svg?style=svg)](https://circleci.com/gh/Pithikos/C-Thread-Pool) # C Thread Pool From b4f1a6494e6457641d885ad8699546afb02ac528 Mon Sep 17 00:00:00 2001 From: "Manos S.H" Date: Tue, 21 Jul 2020 00:54:13 +0100 Subject: [PATCH 13/43] Make CI faster --- tests/memleaks.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/memleaks.sh b/tests/memleaks.sh index b85dac3..397d500 100755 --- a/tests/memleaks.sh +++ b/tests/memleaks.sh @@ -62,7 +62,12 @@ test_thread_free 8 test_thread_free 1 test_thread_free 20 test_thread_free_multi 4 20 -test_thread_free_multi 3 1000 -test_thread_free_multi 100 100 + +# test_thread_free_multi 3 1000 # Takes way too long +test_thread_free_multi 3 200 + +# test_thread_free_multi 100 100 # Takes way too long +test_thread_free_multi 100 20 + echo "No memory leaks" From 25fa679ecadf61d6ca6bd7d8434bcbb1478c9af7 Mon Sep 17 00:00:00 2001 From: "Manos S.H" Date: Tue, 21 Jul 2020 18:50:34 +0100 Subject: [PATCH 14/43] Add info for becoming collaborator --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1240bf7..fc4eb55 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,5 @@ You are very welcome to contribute. If you have a new feature in mind, you can a * For coding style simply try to stick to the conventions you find in the existing codebase. * Tests: A new fix or feature should be covered by tests. If the existing tests are not sufficient, we expect an according test to follow with the pull request. * Documentation: for a new feature please add documentation. For an API change the documentation has to be thorough and super easy to understand. + +If you wish to **get access as a collaborator** feel free to mention it in the issue https://github.com/Pithikos/C-Thread-Pool/issues/78 From 5fbe48196556476ae63fabd9a30023266f4397ac Mon Sep 17 00:00:00 2001 From: nil0x42 Date: Sun, 27 Sep 2020 23:06:38 +0000 Subject: [PATCH 15/43] Use safe snprintf() instead of sprintf() The use of sprintf is considered unsafe. And besides being in this case not vulnerable, CI services such as deepcode.ai will send an annoying alert for projects using thpool, as in this example: https://www.deepcode.ai/app/gh/nil0x42/duplicut/47376326b7e1fe987d60d6244ad76b0bb0b4a9e9/_/%2Fsrc%2Fthpool.c/cpp%2Fdc%2FBufferOverflowUnsafeFunction/321/code The buffer is also bigger than needed: even if `thread_p->id` were to be an uint64_max, the generated string would still fit in 31 bytes (`thread-pool-9223372036854775807`); so buffer was set to 32 bytes instead of 128 --- thpool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thpool.c b/thpool.c index dcb5858..d320f8f 100644 --- a/thpool.c +++ b/thpool.c @@ -317,8 +317,8 @@ static void thread_hold(int sig_id) { static void* thread_do(struct thread* thread_p){ /* Set thread name for profiling and debuging */ - char thread_name[128] = {0}; - sprintf(thread_name, "thread-pool-%d", thread_p->id); + char thread_name[32] = {0}; + snprintf(thread_name, 32, "thread-pool-%d", thread_p->id); #if defined(__linux__) /* Use prctl instead to prevent using _GNU_SOURCE flag and implicit declaration */ From 3d8745b98cb934e6c4e3c986097bd2d7b1d20060 Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Mon, 7 Dec 2020 21:51:28 +1100 Subject: [PATCH 16/43] docs: fix simple typo, successs -> success There is a small typo in thpool.h. Should read `success` rather than `successs`. --- thpool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thpool.h b/thpool.h index 1caee8e..af3e68d 100644 --- a/thpool.h +++ b/thpool.h @@ -62,7 +62,7 @@ threadpool thpool_init(int num_threads); * @param threadpool threadpool to which the work will be added * @param function_p pointer to function to add as work * @param arg_p pointer to an argument - * @return 0 on successs, -1 otherwise. + * @return 0 on success, -1 otherwise. */ int thpool_add_work(threadpool, void (*function_p)(void*), void* arg_p); From 3cff33453884bad82319f195ecc29539e86245f3 Mon Sep 17 00:00:00 2001 From: Andrew Hicks Date: Tue, 16 Mar 2021 20:58:16 -0400 Subject: [PATCH 17/43] Fix error in FreeBSD --- thpool.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/thpool.c b/thpool.c index d320f8f..6eb7a93 100644 --- a/thpool.c +++ b/thpool.c @@ -18,6 +18,8 @@ #include #if defined(__linux__) #include +#elif defined(__FreeBSD__) +#include #endif #include "thpool.h" @@ -325,6 +327,8 @@ static void* thread_do(struct thread* thread_p){ prctl(PR_SET_NAME, thread_name); #elif defined(__APPLE__) && defined(__MACH__) pthread_setname_np(thread_name); +#elif defined(__FreeBSD__) + pthread_set_name_np(pthread_self(), thread_name); #else err("thread_do(): pthread_setname_np is not supported on this system"); #endif From 3f46454ca938b4670022968fbe1d19886339851c Mon Sep 17 00:00:00 2001 From: zlrs Date: Thu, 29 Apr 2021 15:16:58 +0800 Subject: [PATCH 18/43] fix: limit thread name length to 16bytes --- thpool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thpool.c b/thpool.c index d320f8f..9977d0f 100644 --- a/thpool.c +++ b/thpool.c @@ -317,8 +317,8 @@ static void thread_hold(int sig_id) { static void* thread_do(struct thread* thread_p){ /* Set thread name for profiling and debuging */ - char thread_name[32] = {0}; - snprintf(thread_name, 32, "thread-pool-%d", thread_p->id); + char thread_name[16] = {0}; + snprintf(thread_name, 16, "thpool-%d", thread_p->id); #if defined(__linux__) /* Use prctl instead to prevent using _GNU_SOURCE flag and implicit declaration */ From 2ea22f12719fb702450843ba91321b9014f19b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 22 Sep 2022 15:53:38 +0200 Subject: [PATCH 19/43] feat: compatiblity with Mac OS X --- thpool.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/thpool.c b/thpool.c index d320f8f..329f3c6 100644 --- a/thpool.c +++ b/thpool.c @@ -8,7 +8,13 @@ * ********************************/ +#if defined(__APPLE__) +#include +#else +#ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200809L +#endif +#endif #include #include #include From 3853d02bcee0e92f323a5b7c244fa06dde6dc5ca Mon Sep 17 00:00:00 2001 From: Mano Date: Wed, 30 Nov 2022 17:49:04 +0000 Subject: [PATCH 20/43] Increase timeout for tests --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 26df327..2d883bf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,6 +8,7 @@ jobs: - checkout - run: name: Test + no_output_timeout: 3h command: | cd tests/ ./normal_compile.sh From 094a64e3d94e54f9c191bd6a598ab8f2a45930ca Mon Sep 17 00:00:00 2001 From: Mano Date: Wed, 30 Nov 2022 23:47:27 +0000 Subject: [PATCH 21/43] Run tests in parallel --- .circleci/config.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2d883bf..f26b575 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,20 +1,31 @@ version: 2.1 jobs: - test: + test-normal-compile: docker: - image: pithikos/test-c-thread-pool steps: - checkout - run: name: Test - no_output_timeout: 3h + no_output_timeout: 2h command: | cd tests/ ./normal_compile.sh + test-optimized-compile: + docker: + - image: pithikos/test-c-thread-pool + steps: + - checkout + - run: + name: Test + no_output_timeout: 2h + command: | + cd tests/ ./optimized_compile.sh workflows: test: jobs: - - test + - test-normal-compile + - test-optimized-compile From 1ff0984eea514e4831a91c97959ef13dd45cafe7 Mon Sep 17 00:00:00 2001 From: Mano Date: Wed, 30 Nov 2022 23:58:11 +0000 Subject: [PATCH 22/43] Reduce memleaks tests time by ~30% --- tests/src/no_work.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/no_work.c b/tests/src/no_work.c index e055c72..667f0aa 100644 --- a/tests/src/no_work.c +++ b/tests/src/no_work.c @@ -17,7 +17,7 @@ int main(int argc, char *argv[]){ threadpool thpool = thpool_init(num_threads); thpool_destroy(thpool); - sleep(1); // Sometimes main exits before thpool_destroy finished 100% + sleep(0.5); // Sometimes main exits before thpool_destroy finished 100% return 0; } From 8f1bcb1aa4e4c0ee5cfc913b4dae4a9af51d5cfd Mon Sep 17 00:00:00 2001 From: Mano Date: Thu, 1 Dec 2022 00:26:38 +0000 Subject: [PATCH 23/43] Split test_thread_free_multi into 2 separate funcs --- tests/memleaks.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tests/memleaks.sh b/tests/memleaks.sh index 397d500..95fc3e7 100755 --- a/tests/memleaks.sh +++ b/tests/memleaks.sh @@ -28,25 +28,30 @@ function test_thread_free { #threads } +function _test_thread_free_multi { #threads + output=$(valgrind --leak-check=full --track-origins=yes ./test "$1" 2>&1 > /dev/null) + heap_usage=$(echo "$output" | grep "total heap usage") + allocs=$(extract_num "[0-9]* allocs" "$heap_usage") + frees=$(extract_num "[0-9]* frees" "$heap_usage") + if (( "$allocs" == 0 )); then + err "Allocated 0 times. Something is wrong.." "$output" + exit 1 + fi + if (( "$allocs" != "$frees" )); then + err "Allocated $allocs times but freed only $frees" "$output" + exit 1 + fi + #echo "Allocs: $allocs Frees: $frees" +} + + # This is the same with test_many_thread_allocs but multiplied function test_thread_free_multi { #threads #times echo "Testing multiple threads creation and destruction in pool(threads=$1 times=$2)" compile src/no_work.c for ((i = 1; i <= $2; i++)); do python -c "import sys; sys.stdout.write('$i/$2\r')" - output=$(valgrind --leak-check=full --track-origins=yes ./test "$1" 2>&1 > /dev/null) - heap_usage=$(echo "$output" | grep "total heap usage") - allocs=$(extract_num "[0-9]* allocs" "$heap_usage") - frees=$(extract_num "[0-9]* frees" "$heap_usage") - if (( "$allocs" == 0 )); then - err "Allocated 0 times. Something is wrong.." "$output" - exit 1 - fi - if (( "$allocs" != "$frees" )); then - err "Allocated $allocs times but freed only $frees" "$output" - exit 1 - fi - #echo "Allocs: $allocs Frees: $frees" + _test_thread_free_multi $1 done echo } From bd7fdc0b695cb3b23ed460762936c16456ad5e7d Mon Sep 17 00:00:00 2001 From: Mano Date: Thu, 1 Dec 2022 00:34:02 +0000 Subject: [PATCH 24/43] Re-increase no_work sleep to give time for thpool to be destroyed --- tests/src/no_work.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/no_work.c b/tests/src/no_work.c index 667f0aa..7b7471e 100644 --- a/tests/src/no_work.c +++ b/tests/src/no_work.c @@ -17,7 +17,7 @@ int main(int argc, char *argv[]){ threadpool thpool = thpool_init(num_threads); thpool_destroy(thpool); - sleep(0.5); // Sometimes main exits before thpool_destroy finished 100% + sleep(0.8); // Sometimes main exits before thpool_destroy finished 100% return 0; } From 230dd7e643af9282eed29ef628166ab1b24c7368 Mon Sep 17 00:00:00 2001 From: Mano Date: Thu, 1 Dec 2022 01:13:03 +0000 Subject: [PATCH 25/43] Increase sleep time to 1.0 again to solve false negatives --- tests/src/no_work.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/no_work.c b/tests/src/no_work.c index 7b7471e..e055c72 100644 --- a/tests/src/no_work.c +++ b/tests/src/no_work.c @@ -17,7 +17,7 @@ int main(int argc, char *argv[]){ threadpool thpool = thpool_init(num_threads); thpool_destroy(thpool); - sleep(0.8); // Sometimes main exits before thpool_destroy finished 100% + sleep(1); // Sometimes main exits before thpool_destroy finished 100% return 0; } From 4f4082e817b1c727516e368d60493aeb7d3cd099 Mon Sep 17 00:00:00 2001 From: Mano Date: Thu, 1 Dec 2022 01:15:23 +0000 Subject: [PATCH 26/43] Run memleak tests in parallel where possible --- tests/memleaks.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/memleaks.sh b/tests/memleaks.sh index 95fc3e7..08c0c11 100755 --- a/tests/memleaks.sh +++ b/tests/memleaks.sh @@ -35,11 +35,11 @@ function _test_thread_free_multi { #threads frees=$(extract_num "[0-9]* frees" "$heap_usage") if (( "$allocs" == 0 )); then err "Allocated 0 times. Something is wrong.." "$output" - exit 1 + return 1 fi if (( "$allocs" != "$frees" )); then err "Allocated $allocs times but freed only $frees" "$output" - exit 1 + return 1 fi #echo "Allocs: $allocs Frees: $frees" } @@ -49,9 +49,26 @@ function _test_thread_free_multi { #threads function test_thread_free_multi { #threads #times echo "Testing multiple threads creation and destruction in pool(threads=$1 times=$2)" compile src/no_work.c - for ((i = 1; i <= $2; i++)); do + pids=() + + # Run tests in p + for (( i = 1; i <= "$2"; i++ )); do + + # Run test in background python -c "import sys; sys.stdout.write('$i/$2\r')" - _test_thread_free_multi $1 + _test_thread_free_multi "$1" & + pids+=($!) + + # Wait for 10 background jobs to finish + if (( "$i" % 10 == 0 )); then + for pid in ${pids[@]}; do + wait $pid + if (( $? != 0 )); then + err "Test failed" "Test failed" + fi + done + pids=() + fi done echo } From b2827e9960213416c5d83fb23e613a36bdbad6d3 Mon Sep 17 00:00:00 2001 From: Mano Date: Thu, 1 Dec 2022 09:53:17 +0000 Subject: [PATCH 27/43] Thread-heavy tests should not parallelize too much --- tests/memleaks.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/memleaks.sh b/tests/memleaks.sh index 08c0c11..2869155 100755 --- a/tests/memleaks.sh +++ b/tests/memleaks.sh @@ -46,10 +46,11 @@ function _test_thread_free_multi { #threads # This is the same with test_many_thread_allocs but multiplied -function test_thread_free_multi { #threads #times +function test_thread_free_multi { #threads #times #nparallel echo "Testing multiple threads creation and destruction in pool(threads=$1 times=$2)" compile src/no_work.c pids=() + nparallel="${3:-10}" # Run tests in p for (( i = 1; i <= "$2"; i++ )); do @@ -89,7 +90,7 @@ test_thread_free_multi 4 20 test_thread_free_multi 3 200 # test_thread_free_multi 100 100 # Takes way too long -test_thread_free_multi 100 20 +test_thread_free_multi 100 20 1 echo "No memory leaks" From b2f44889cb0f7ff30963228911625a64bfff81e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 19 Dec 2022 17:11:37 +0100 Subject: [PATCH 28/43] fix: set the SA_ONSTACK flag --- thpool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thpool.c b/thpool.c index db96848..71ddf90 100644 --- a/thpool.c +++ b/thpool.c @@ -341,7 +341,7 @@ static void* thread_do(struct thread* thread_p){ /* Register signal handler */ struct sigaction act; sigemptyset(&act.sa_mask); - act.sa_flags = 0; + act.sa_flags = SA_ONSTACK; act.sa_handler = thread_hold; if (sigaction(SIGUSR1, &act, NULL) == -1) { err("thread_do(): cannot handle SIGUSR1"); From 78336465c83440f614e3068259f96a31e44a1444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 19 Dec 2022 21:36:19 +0100 Subject: [PATCH 29/43] ci: switch to GitHub Actions --- .circleci/Dockerfile | 4 ---- .circleci/README.md | 4 ---- .circleci/config.yml | 31 ------------------------------- .github/workflows/tests.yml | 19 +++++++++++++++++++ README.md | 2 +- 5 files changed, 20 insertions(+), 40 deletions(-) delete mode 100644 .circleci/Dockerfile delete mode 100644 .circleci/README.md delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/tests.yml diff --git a/.circleci/Dockerfile b/.circleci/Dockerfile deleted file mode 100644 index 5b3193c..0000000 --- a/.circleci/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM ubuntu - -RUN apt-get update && \ - apt-get -y install gcc valgrind time python diff --git a/.circleci/README.md b/.circleci/README.md deleted file mode 100644 index fa77c85..0000000 --- a/.circleci/README.md +++ /dev/null @@ -1,4 +0,0 @@ -Build and push container - - docker build -t pithikos/test-c-thread-pool . - docker push pithikos/test-c-thread-pool diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index f26b575..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: 2.1 - -jobs: - test-normal-compile: - docker: - - image: pithikos/test-c-thread-pool - steps: - - checkout - - run: - name: Test - no_output_timeout: 2h - command: | - cd tests/ - ./normal_compile.sh - test-optimized-compile: - docker: - - image: pithikos/test-c-thread-pool - steps: - - checkout - - run: - name: Test - no_output_timeout: 2h - command: | - cd tests/ - ./optimized_compile.sh - -workflows: - test: - jobs: - - test-normal-compile - - test-optimized-compile diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..86b383b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,19 @@ +name: Tests + +on: + push: + pull_request: + +jobs: + test-normal-compile: + runs-on: ubuntu-latest + steps: + - name: Run tests with standard compilation flags + working-directory: tests/ + run: ./normal_compile.sh + test-optimized-compile: + runs-on: ubuntu-latest + steps: + - name: Run tests with optimized compilation flags + working-directory: tests/ + run: ./optimized_compile.sh diff --git a/README.md b/README.md index fc4eb55..43bc7ea 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![CircleCI](https://circleci.com/gh/Pithikos/C-Thread-Pool.svg?style=svg)](https://circleci.com/gh/Pithikos/C-Thread-Pool) +[[![GitHub Actions](https://github.com/Pithikos/C-Thread-Pool/workflows/tests/badge.svg?branch=master)](https://github.com/api-platform/core/actions?query=workflow%3Atests+branch%3Amaster) # C Thread Pool From 3f826f040ed668c124fc9ed1ada237085d267a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 19 Dec 2022 21:38:26 +0100 Subject: [PATCH 30/43] add missing checkout action --- .github/workflows/tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 86b383b..ab53edc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,12 +8,14 @@ jobs: test-normal-compile: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 - name: Run tests with standard compilation flags working-directory: tests/ run: ./normal_compile.sh test-optimized-compile: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 - name: Run tests with optimized compilation flags working-directory: tests/ run: ./optimized_compile.sh From 4ea14a25f130087bf5933afe3e6208d3ed0e6e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 19 Dec 2022 21:41:43 +0100 Subject: [PATCH 31/43] install Valgrind --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ab53edc..a53b958 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,6 +9,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Install Valgrind + run: sudo apt install valgrind - name: Run tests with standard compilation flags working-directory: tests/ run: ./normal_compile.sh @@ -16,6 +18,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Install Valgrind + run: sudo apt install valgrind - name: Run tests with optimized compilation flags working-directory: tests/ run: ./optimized_compile.sh From ca34e53025f7688c0d28dc7acd1900be0fa54d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 19 Dec 2022 21:47:43 +0100 Subject: [PATCH 32/43] use apt-get instead of apt --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a53b958..3409c90 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Install Valgrind - run: sudo apt install valgrind + run: sudo apt-get install -y valgrind - name: Run tests with standard compilation flags working-directory: tests/ run: ./normal_compile.sh @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Install Valgrind - run: sudo apt install valgrind + run: sudo apt-get install -y valgrind - name: Run tests with optimized compilation flags working-directory: tests/ run: ./optimized_compile.sh From 22092e7729f62e3d0363b289e793273a92a353b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 19 Dec 2022 22:06:56 +0100 Subject: [PATCH 33/43] indentation --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3409c90..fb1af23 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,6 +14,7 @@ jobs: - name: Run tests with standard compilation flags working-directory: tests/ run: ./normal_compile.sh + test-optimized-compile: runs-on: ubuntu-latest steps: From 3fe36a50aff6df4824e307a6d716e22aa441b21a Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Sun, 25 Dec 2022 23:50:33 +0100 Subject: [PATCH 34/43] docs: fix typos --- tests/src/conc_increment.c | 2 +- tests/src/pause_resume.c | 2 +- thpool.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/src/conc_increment.c b/tests/src/conc_increment.c index 5caf762..21034e3 100644 --- a/tests/src/conc_increment.c +++ b/tests/src/conc_increment.c @@ -20,7 +20,7 @@ int main(int argc, char *argv[]){ char* p; if (argc != 3){ - puts("This testfile needs excactly two arguments"); + puts("This testfile needs exactly two arguments"); exit(1); } int num_jobs = strtol(argv[1], &p, 10); diff --git a/tests/src/pause_resume.c b/tests/src/pause_resume.c index 282c398..d96689a 100644 --- a/tests/src/pause_resume.c +++ b/tests/src/pause_resume.c @@ -24,7 +24,7 @@ int main(int argc, char *argv[]){ char* p; if (argc != 2){ - puts("This testfile needs excactly one arguments"); + puts("This testfile needs exactly one arguments"); exit(1); } int num_threads = strtol(argv[1], &p, 10); diff --git a/thpool.c b/thpool.c index db96848..59e2e55 100644 --- a/thpool.c +++ b/thpool.c @@ -211,7 +211,7 @@ void thpool_wait(thpool_* thpool_p){ /* Destroy the threadpool */ void thpool_destroy(thpool_* thpool_p){ - /* No need to destory if it's NULL */ + /* No need to destroy if it's NULL */ if (thpool_p == NULL) return ; volatile int threads_total = thpool_p->num_threads_alive; @@ -260,7 +260,7 @@ void thpool_pause(thpool_* thpool_p) { /* Resume all threads in threadpool */ void thpool_resume(thpool_* thpool_p) { // resuming a single threadpool hasn't been - // implemented yet, meanwhile this supresses + // implemented yet, meanwhile this suppresses // the warnings (void)thpool_p; @@ -322,7 +322,7 @@ static void thread_hold(int sig_id) { */ static void* thread_do(struct thread* thread_p){ - /* Set thread name for profiling and debuging */ + /* Set thread name for profiling and debugging */ char thread_name[16] = {0}; snprintf(thread_name, 16, "thpool-%d", thread_p->id); From 59683c790d56f853aaab371d7462b137ea093182 Mon Sep 17 00:00:00 2001 From: Zijie Wu Date: Tue, 27 Jun 2023 15:44:47 -0700 Subject: [PATCH 35/43] Fix typo --- thpool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thpool.c b/thpool.c index 59e2e55..5436e44 100644 --- a/thpool.c +++ b/thpool.c @@ -314,7 +314,7 @@ static void thread_hold(int sig_id) { /* What each thread is doing * -* In principle this is an endless loop. The only time this loop gets interuppted is once +* In principle this is an endless loop. The only time this loop gets interrupted is once * thpool_destroy() is invoked or the program exits. * * @param thread thread that will run this function From 734bdf4d955b7af31f1a438799183a5b42a556d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 6 Oct 2023 18:19:59 +0200 Subject: [PATCH 36/43] feat: make the thread name configurable --- thpool.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/thpool.c b/thpool.c index 59e2e55..716a487 100644 --- a/thpool.c +++ b/thpool.c @@ -40,6 +40,13 @@ #define err(str) #endif +#ifndef THPOOL_THREAD_NAME +#define THPOOL_THREAD_NAME thpool +#endif + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) + static volatile int threads_keepalive; static volatile int threads_on_hold; @@ -324,7 +331,8 @@ static void* thread_do(struct thread* thread_p){ /* Set thread name for profiling and debugging */ char thread_name[16] = {0}; - snprintf(thread_name, 16, "thpool-%d", thread_p->id); + + snprintf(thread_name, 16, TOSTRING(THPOOL_THREAD_NAME) "-%d", thread_p->id); #if defined(__linux__) /* Use prctl instead to prevent using _GNU_SOURCE flag and implicit declaration */ From 96146f08b4ef25fddfdb87c809bf792d8493090c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 18 Dec 2023 01:07:28 +0100 Subject: [PATCH 37/43] fix: properly destroy mutex during reset --- thpool.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/thpool.c b/thpool.c index 59e2e55..e671e51 100644 --- a/thpool.c +++ b/thpool.c @@ -520,6 +520,8 @@ static void bsem_init(bsem *bsem_p, int value) { /* Reset semaphore to 0 */ static void bsem_reset(bsem *bsem_p) { + pthread_mutex_destroy(&(bsem_p->mutex)); + pthread_cond_destroy(&(bsem_p->cond)); bsem_init(bsem_p, 0); } From 81b76df72ed008302bc6838442784eee69f9ebf9 Mon Sep 17 00:00:00 2001 From: Manos Date: Mon, 18 Dec 2023 10:48:01 +0000 Subject: [PATCH 38/43] Revert "fix: set the SA_ONSTACK flag" --- thpool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thpool.c b/thpool.c index 004b4bc..8bc782a 100644 --- a/thpool.c +++ b/thpool.c @@ -349,7 +349,7 @@ static void* thread_do(struct thread* thread_p){ /* Register signal handler */ struct sigaction act; sigemptyset(&act.sa_mask); - act.sa_flags = SA_ONSTACK; + act.sa_flags = 0; act.sa_handler = thread_hold; if (sigaction(SIGUSR1, &act, NULL) == -1) { err("thread_do(): cannot handle SIGUSR1"); From 222340137b832ca25d147cd3a7c03a40d2477fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 18 Dec 2023 13:51:00 +0100 Subject: [PATCH 39/43] Reapply "fix: set the SA_ONSTACK flag" This reverts commit 81b76df72ed008302bc6838442784eee69f9ebf9. --- thpool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thpool.c b/thpool.c index 8bc782a..004b4bc 100644 --- a/thpool.c +++ b/thpool.c @@ -349,7 +349,7 @@ static void* thread_do(struct thread* thread_p){ /* Register signal handler */ struct sigaction act; sigemptyset(&act.sa_mask); - act.sa_flags = 0; + act.sa_flags = SA_ONSTACK; act.sa_handler = thread_hold; if (sigaction(SIGUSR1, &act, NULL) == -1) { err("thread_do(): cannot handle SIGUSR1"); From d3f1967cd37833a81eb8b0df26cf5206a53e8838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 18 Dec 2023 13:24:33 +0100 Subject: [PATCH 40/43] fix: ensure that SA_ONSTACK is declared --- thpool.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/thpool.c b/thpool.c index 004b4bc..0d60a65 100644 --- a/thpool.c +++ b/thpool.c @@ -14,6 +14,9 @@ #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200809L #endif +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 500 +#endif #endif #include #include From 40cd44cf891200bc68980593daaccaf810808961 Mon Sep 17 00:00:00 2001 From: Manos Date: Mon, 18 Dec 2023 14:27:54 +0100 Subject: [PATCH 41/43] Fix badge --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43bc7ea..851e54e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -[[![GitHub Actions](https://github.com/Pithikos/C-Thread-Pool/workflows/tests/badge.svg?branch=master)](https://github.com/api-platform/core/actions?query=workflow%3Atests+branch%3Amaster) +[![GitHub Actions](https://github.com/Pithikos/C-Thread-Pool/workflows/Tests/badge.svg?branch=master)](https://github.com/Pithikos/C-Thread-Pool/actions?query=workflow%3Atests+branch%3Amaster) + # C Thread Pool From 29e85feeea48ce6a07adc1541574026e4aab265a Mon Sep 17 00:00:00 2001 From: Manos Date: Mon, 18 Dec 2023 15:04:46 +0100 Subject: [PATCH 42/43] Merge ghost commits --- thpool.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/thpool.c b/thpool.c index 4c1aef7..52163f7 100644 --- a/thpool.c +++ b/thpool.c @@ -24,7 +24,8 @@ #include #if defined(__linux__) #include -#elif defined(__FreeBSD__) +#endif +#if defined(__FreeBSD__) || defined(__OpenBSD__) #include #endif @@ -341,8 +342,8 @@ static void* thread_do(struct thread* thread_p){ prctl(PR_SET_NAME, thread_name); #elif defined(__APPLE__) && defined(__MACH__) pthread_setname_np(thread_name); -#elif defined(__FreeBSD__) - pthread_set_name_np(pthread_self(), thread_name); +#elif defined(__FreeBSD__) || defined(__OpenBSD__) + pthread_set_name_np(thread_p->pthread, thread_name); #else err("thread_do(): pthread_setname_np is not supported on this system"); #endif From 6b45b0746cdac3643944f4feb4c100aef8f9bf6c Mon Sep 17 00:00:00 2001 From: Manos Date: Mon, 18 Dec 2023 14:27:54 +0100 Subject: [PATCH 43/43] Fix badge --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43bc7ea..051d179 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -[[![GitHub Actions](https://github.com/Pithikos/C-Thread-Pool/workflows/tests/badge.svg?branch=master)](https://github.com/api-platform/core/actions?query=workflow%3Atests+branch%3Amaster) +[![GitHub Actions](https://github.com/Pithikos/C-Thread-Pool/workflows/tests.yml/badge.svg?branch=master)](https://github.com/Pithikos/C-Thread-Pool/actions?query=workflow%3Atests+branch%3Amaster) + # C Thread Pool