From f6fe977c7880093367b28baa8a64fa7618d6fb9e Mon Sep 17 00:00:00 2001 From: deadwood Date: Fri, 14 Nov 2014 21:02:47 +0000 Subject: [PATCH] test: add pthread test from contrib's pthread version git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@49795 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- test/mmakefile.src | 5 ++-- test/pthreadtest.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 test/pthreadtest.c diff --git a/test/mmakefile.src b/test/mmakefile.src index 0f0bb98f77..6dbe611ddf 100644 --- a/test/mmakefile.src +++ b/test/mmakefile.src @@ -78,7 +78,8 @@ COMMONTESTFILES := \ mountlist \ smult \ crashtest \ - openlocale + openlocale \ + pthreadtest SHTESTFILES=\ pcilist \ @@ -101,7 +102,7 @@ USER_CFLAGS += -DADATE="\"$(shell date '+%d.%m.%Y')\"" %build_progs mmake=test-common \ files=$(COMMONTESTFILES) targetdir=$(EXEDIR) \ - uselibs="coolimagesstatic hiddstubs" + uselibs="coolimagesstatic hiddstubs pthread" %build_progs mmake=test-sh \ files=$(SHTESTFILES) targetdir=$(EXEDIR) \ diff --git a/test/pthreadtest.c b/test/pthreadtest.c new file mode 100644 index 0000000000..c99a469725 --- /dev/null +++ b/test/pthreadtest.c @@ -0,0 +1,79 @@ +/* + Copyright © 2007-2014, The AROS Development Team. All rights reserved. + $Id$ +*/ + + +#include +#include +#include + +void *thread_func1( void *vptr_args ); +void *thread_func2( void *vptr_args ); + +volatile int m; + +int main ( void ) +{ + int j; + + pthread_t thread1, thread2; + + pthread_create( &thread1, NULL, &thread_func1, NULL ); + printf("thread 1 created.. thread: %d\n", thread1); + + pthread_create( &thread2, NULL, &thread_func2, NULL ); + printf("thread 2 created.. thread: %d\n", thread2); + + + for( j= 0; j < 20; ++j ) + { + printf("a\n"); + + for( m= 99999999; m; --m ); /* use some CPU time */ + + printf("trying to cancel thread 1\n"); + pthread_cancel( thread1 ); + } + + + printf("join thread 2\n"); + pthread_join( thread2, NULL ); + + printf("finished!\n"); + + return 0; +} + +volatile int f1, f2; + +void *thread_func1( void *vptr_args ) +{ + int j; + + for( j= 0; j < 20; ++j ) + { + printf("b\n"); + + for( f1= 99999999; f1; --f1 ); /* use some CPU time */ + } + + printf("func1 end\n"); + return NULL; +} + +void *thread_func2( void *vptr_args ) +{ + int j; + + for( j= 0; j < 20; ++j ) + { + printf("c\n"); + + for( f2= 199999999; f2; --f2 ); /* use some CPU time */ + } + + printf("func2 end\n"); + return NULL; +} + -- 2.11.4.GIT