mirror of
https://github.com/Pithikos/C-Thread-Pool
synced 2024-11-25 06:49:37 +03:00
Works now even when compiled with optimization flags
This commit is contained in:
parent
90174270f6
commit
746cf897c3
@ -1,11 +1,25 @@
|
||||
Tests
|
||||
------------------------------------------------------------------------
|
||||
|
||||
For memory leaks run `./memleaks`. This might take a while since valgrind
|
||||
needs one second to init each thread.
|
||||
**Case tests**
|
||||
````
|
||||
memleaks - Will run tests for memory leaks. valgrind is being used for this.
|
||||
Notice that valgrind requires one second to init each thread.
|
||||
threadpool - Will run general functional tests for the threadpool.
|
||||
pause_resume - Will test the synchronisation of the threadpool from the user.
|
||||
wait - Will run tests to assuse that the wait() function works correctly.
|
||||
|
||||
For the general functional tests run `./threadpool`.
|
||||
````
|
||||
|
||||
**On errors:**
|
||||
|
||||
**Compilation cases**
|
||||
````
|
||||
normal_compile - Will run all tests above against a simply compiled threadpool.
|
||||
optimized_compile - Will run all tests but against a binary that was compiled
|
||||
with optimization flags.
|
||||
````
|
||||
|
||||
|
||||
**On errors**
|
||||
|
||||
Check the created log file `error.log`
|
||||
|
@ -37,3 +37,8 @@ function err { #string #log
|
||||
echo "$2" >> error.log
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
function compile { #cfilepath
|
||||
gcc $COMPILATION_FLAGS "$1" ../thpool.c -pthread -o test
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
function test_thread_free { #threads
|
||||
echo "Testing creation and destruction of threads(=$1)"
|
||||
gcc src/no_work.c ../thpool.c -pthread -o test
|
||||
compile src/no_work.c
|
||||
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")
|
||||
@ -32,7 +32,7 @@ function test_thread_free { #threads
|
||||
# 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)"
|
||||
gcc src/no_work.c ../thpool.c -pthread -o test
|
||||
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)
|
||||
|
16
tests/normal_compile
Executable file
16
tests/normal_compile
Executable file
@ -0,0 +1,16 @@
|
||||
#! /bin/bash
|
||||
|
||||
#
|
||||
# This will run all tests for a simple compilation
|
||||
#
|
||||
|
||||
|
||||
|
||||
# ---------------------------- Tests -----------------------------------
|
||||
|
||||
. threadpool
|
||||
. pause_resume
|
||||
. memleaks
|
||||
. wait
|
||||
|
||||
echo "No errors"
|
15
tests/optimized_compile
Executable file
15
tests/optimized_compile
Executable file
@ -0,0 +1,15 @@
|
||||
#! /bin/bash
|
||||
|
||||
#
|
||||
# This file will run all tests but with a binary that has
|
||||
# been compiled with optimization flags.
|
||||
#
|
||||
|
||||
|
||||
|
||||
# ---------------------------- Tests -----------------------------------
|
||||
|
||||
COMPILATION_FLAGS='-g -O'
|
||||
. normal_compile
|
||||
|
||||
echo "No optimization errors"
|
@ -13,7 +13,7 @@
|
||||
|
||||
function test_pause_resume_est7secs { #threads
|
||||
echo "Pause and resume test for 7 secs with $1 threads"
|
||||
gcc src/pause_resume.c ../thpool.c -pthread -o test
|
||||
compile src/pause_resume.c
|
||||
realsecs=$(/usr/bin/time -f '%e' ./test "$1" 2>&1 > /dev/null)
|
||||
threshold=1.00 # in secs
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
function test_mass_addition { #endsum #threads
|
||||
echo "Adding up to $1 with $2 threads"
|
||||
gcc src/conc_increment.c ../thpool.c -pthread -o test
|
||||
compile src/conc_increment.c
|
||||
output=$(./test $1 $2)
|
||||
num=$(echo $output | awk '{print $(NF)}')
|
||||
if [ "$num" == "$1" ]; then
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
function test_wait_each_job { #threads #jobs
|
||||
echo "Will test waiting for each job ($1 threads, $2 jobs)"
|
||||
gcc src/wait.c ../thpool.c -pthread -o test
|
||||
compile src/wait.c
|
||||
realsecs=$(time_exec ./test $2 $1 1)
|
||||
threshold=1.00 # in secs
|
||||
|
||||
@ -29,7 +29,7 @@ function test_wait_each_job { #threads #jobs
|
||||
|
||||
function test_wait_pool { #threads #jobs
|
||||
echo "Will test waiting for whole threadpool ($1 threads, $2 jobs)"
|
||||
gcc src/wait.c ../thpool.c -pthread -o test
|
||||
compile src/wait.c
|
||||
realsecs=$(time_exec ./test $2 $1 0)
|
||||
threshold=1.00 # in secs
|
||||
|
||||
|
4
thpool.c
4
thpool.c
@ -69,8 +69,8 @@ typedef struct thread{
|
||||
/* Threadpool */
|
||||
typedef struct thpool_{
|
||||
thread** threads; /* pointer to threads */
|
||||
int num_threads_alive; /* threads currently alive */
|
||||
int num_threads_working; /* threads currently working */
|
||||
volatile int num_threads_alive; /* threads currently alive */
|
||||
volatile int num_threads_working; /* threads currently working */
|
||||
pthread_mutex_t thcount_lock; /* used for thread count etc */
|
||||
jobqueue* jobqueue_p; /* pointer to the job queue */
|
||||
} thpool_;
|
||||
|
Loading…
Reference in New Issue
Block a user