Refactored tests

This commit is contained in:
pithikos 2015-01-16 18:21:34 +00:00
parent f269de73f8
commit 42e7937bca
4 changed files with 12 additions and 14 deletions

View File

@ -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){

View File

@ -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"

View File

@ -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);

View File

@ -6,7 +6,7 @@
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
char* p; char* p;
if (argc != 2){ if (argc != 2){
puts("This testfile needs excactly one arguments"); puts("This testfile needs excactly one arguments");
@ -14,10 +14,9 @@ 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%
return 0; return 0;