From: Julian Seward Date: Wed, 10 Apr 2002 12:14:34 +0000 (+0000) Subject: From the OReilly book, page 15. Uses _create and _join. X-Git-Tag: svn/VALGRIND_1_0_3~398 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f0608782913e72bf5b5afb4a9c09367e04f3885;p=thirdparty%2Fvalgrind.git From the OReilly book, page 15. Uses _create and _join. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@48 --- diff --git a/tests/pth_simple_threads.c b/tests/pth_simple_threads.c new file mode 100644 index 0000000000..e42ae26b7e --- /dev/null +++ b/tests/pth_simple_threads.c @@ -0,0 +1,44 @@ + +#include +#include + +int r1 = 0, r2 = 0; + +void do_one_thing ( int* ntimes ) +{ + int i, j, x; + for (i = 0; i < 4; i++) { + printf ("doing one thing\n"); + for (j = 0; j < 100000; j++) x = x + i; + (*ntimes)++; + } +} + +void do_another_thing ( int* ntimes ) +{ + int i, j, x; + for (i = 0; i < 4; i++) { + printf ("doing another\n"); + for (j = 0; j < 100000; j++) x = x + i; + (*ntimes)++; + } +} + +void do_wrap_up ( int one_times, int another_times ) +{ + int total = one_times + another_times; + printf("wrap up: one thing %d, another %d, total %d\n", + one_times, another_times, total ); +} + +int main ( void ) +{ + pthread_t t1, t2; + pthread_create( &t1, NULL, (void*)do_one_thing, (void*)&r1 ); + pthread_create( &t2, NULL, (void*)do_another_thing, (void*)&r2 ); + // while (1) {} + pthread_join(t1, NULL); + pthread_join(t2, NULL); + do_wrap_up(r1,r2); + return 0; +}