mirror of
https://github.com/Pithikos/C-Thread-Pool
synced 2024-11-22 05:31:18 +03:00
Refactored tests
This commit is contained in:
parent
f269de73f8
commit
42e7937bca
@ -6,7 +6,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
/* This showcasts this issue: https://sourceware.org/ml/glibc-bugs/2007-04/msg00036.html */
|
/* This showcasts this issue: https://sourceware.org/ml/glibc-bugs/2007-04/msg00036.html */
|
||||||
/* Alsoe here: http://stackoverflow.com/questions/27803819/pthreads-leak-memory-even-if-used-correctly/27804629 */
|
/* Also here: http://stackoverflow.com/questions/27803819/pthreads-leak-memory-even-if-used-correctly/27804629 */
|
||||||
|
|
||||||
volatile int threads_keepalive = 1;
|
volatile int threads_keepalive = 1;
|
||||||
|
|
||||||
@ -14,7 +14,6 @@ void* thread_do(void *arg){
|
|||||||
while(threads_keepalive)
|
while(threads_keepalive)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
|
@ -60,5 +60,6 @@ test_thread_free 1
|
|||||||
test_thread_free 20
|
test_thread_free 20
|
||||||
test_thread_free_multi 4 20
|
test_thread_free_multi 4 20
|
||||||
test_thread_free_multi 3 1000
|
test_thread_free_multi 3 1000
|
||||||
|
test_thread_free_multi 100 100
|
||||||
|
|
||||||
echo "No memory leaks"
|
echo "No memory leaks"
|
||||||
|
@ -22,18 +22,17 @@ int main(int argc, char *argv[]){
|
|||||||
puts("This testfile needs excactly two arguments");
|
puts("This testfile needs excactly two arguments");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
int jobs = strtol(argv[1], &p, 10);
|
int num_jobs = strtol(argv[1], &p, 10);
|
||||||
int threads = strtol(argv[2], &p, 10);
|
int num_threads = strtol(argv[2], &p, 10);
|
||||||
|
|
||||||
thpool_t* thpool;
|
thpool threadpool = thpool_init(num_threads);
|
||||||
thpool = thpool_init(threads);
|
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
for (n=0; n<jobs; n++){
|
for (n=0; n<num_jobs; n++){
|
||||||
thpool_add_work(thpool, (void*)increment, NULL);
|
thpool_add_work(threadpool, (void*)increment, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
thpool_wait(thpool);
|
thpool_wait(threadpool);
|
||||||
|
|
||||||
printf("%d\n", sum);
|
printf("%d\n", sum);
|
||||||
|
|
||||||
|
@ -14,9 +14,8 @@ int main(int argc, char *argv[]){
|
|||||||
}
|
}
|
||||||
int threads = strtol(argv[1], &p, 10);
|
int threads = strtol(argv[1], &p, 10);
|
||||||
|
|
||||||
thpool_t* thpool;
|
thpool threadpool = thpool_init(threads);
|
||||||
thpool = thpool_init(threads);
|
thpool_destroy(threadpool);
|
||||||
thpool_destroy(thpool);
|
|
||||||
|
|
||||||
sleep(1); // Sometimes main exits before thpool_destroy finished 100%
|
sleep(1); // Sometimes main exits before thpool_destroy finished 100%
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user