-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into g88_trying_to_make_keepalive_local
- Loading branch information
Showing
10 changed files
with
154 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test-normal-compile: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Valgrind | ||
run: sudo apt-get install -y valgrind | ||
- 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: Install Valgrind | ||
run: sudo apt-get install -y valgrind | ||
- name: Run tests with optimized compilation flags | ||
working-directory: tests/ | ||
run: ./optimized_compile.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-------------->| | | ||
|___________| | |.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
### 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. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.