Author: sewardj Date: 2007-10-30 19:31:43 +0000 (Tue, 30 Oct 2007) New Revision: 7057
Log: Add a test for pthread_once behaviour. Added: branches/THRCHECK/thrcheck/tests/tc21_pthonce.c branches/THRCHECK/thrcheck/tests/tc21_pthonce.stderr.exp-glibc25-amd64 branches/THRCHECK/thrcheck/tests/tc21_pthonce.stdout.exp branches/THRCHECK/thrcheck/tests/tc21_pthonce.vgtest Modified: branches/THRCHECK/thrcheck/tests/Makefile.am Modified: branches/THRCHECK/thrcheck/tests/Makefile.am =================================================================== --- branches/THRCHECK/thrcheck/tests/Makefile.am 2007-10-30 19:08:01 UTC (rev 7056) +++ branches/THRCHECK/thrcheck/tests/Makefile.am 2007-10-30 19:31:43 UTC (rev 7057) @@ -69,9 +69,10 @@ tc19_shadowmem.stderr.exp-glibc25-amd64 \ tc19_shadowmem.stderr.exp-glibc25-x86 \ tc20_verifywrap.vgtest tc20_verifywrap.stdout.exp \ - tc20_verifywrap.stderr.exp-glibc25-amd64 + tc20_verifywrap.stderr.exp-glibc25-amd64 \ + tc21_pthonce.vgtest tc21_pthonce.stdout.exp \ + tc21_pthonce.stderr.exp-glibc25-amd64 - check_PROGRAMS = \ hg01_all_ok \ hg02_deadlock \ @@ -98,7 +99,8 @@ tc17_sembar \ tc18_semabuse \ tc19_shadowmem \ - tc20_verifywrap + tc20_verifywrap \ + tc21_pthonce AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include \ -I$(top_srcdir)/coregrind -I$(top_builddir)/include \ Added: branches/THRCHECK/thrcheck/tests/tc21_pthonce.c =================================================================== --- branches/THRCHECK/thrcheck/tests/tc21_pthonce.c (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc21_pthonce.c 2007-10-30 19:31:43 UTC (rev 7057) @@ -0,0 +1,80 @@ + +/* This really exists to check that Thrcheck behaves plausibly + with pthread_once calls. Which it appears to. + + The original source of this program is as shown below, although it + has been modified somewhat. See + http://www.oreilly.com/pub/a/oreilly/ask_tim/2001/codepolicy.html + for OReilly's policy on using bits of their code examples. +*/ + + +/******************************************************** + * An example source module to accompany... + * + * "Using POSIX Threads: Programming with Pthreads" + * by Brad Nichols, Dick Buttlar, Jackie Farrell + * O'Reilly & Associates, Inc. + * + ******************************************************** + * once_exam.c + * + * An example of using the pthreads_once() call to execute an + * initialization procedure. + * + * A program spawns multiple threads and each one tries to + * execute the routine welcome() using the once call. Only + * the first thread into the once routine will actually + * execute welcome(). + * + * The program's main thread synchronizes its exit with the + * exit of the threads using the pthread_join() operation. + * +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <assert.h> + +#include <pthread.h> + +#define NUM_THREADS 4 + +static pthread_once_t welcome_once_block = PTHREAD_ONCE_INIT; + +static int unprotected1 = 0; +static int unprotected2 = 0; + +void welcome(void) { + printf("welcome: Welcome\n"); + unprotected1++; /* this is harmless */ +} + +void* child ( void* argV ) { + int r= pthread_once(&welcome_once_block, welcome); assert(!r); + printf("child: Hi, I'm thread %d\n", *(int*)argV); + unprotected2++; /* whereas this is a race */ + return NULL; +} + +int main ( void ) { + int *id_arg, i, r; + pthread_t threads[NUM_THREADS]; + + id_arg = (int *)malloc(NUM_THREADS*sizeof(int)); + + for (i = 0; i < NUM_THREADS; i++) { + id_arg[i] = i; + r= pthread_create(&threads[i], NULL, child, &id_arg[i]); + assert(!r); + } + + for (i = 0; i < NUM_THREADS; i++) { + pthread_join(threads[i], NULL); + //printf("main: joined to thread %d\n", i); + } + printf("main: Goodbye\n"); + return 0; +} Added: branches/THRCHECK/thrcheck/tests/tc21_pthonce.stderr.exp-glibc25-amd64 =================================================================== --- branches/THRCHECK/thrcheck/tests/tc21_pthonce.stderr.exp-glibc25-amd64 (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc21_pthonce.stderr.exp-glibc25-amd64 2007-10-30 19:31:43 UTC (rev 7057) @@ -0,0 +1,26 @@ + +Thread #2 was created + at 0x........: clone (in /...libc...) + by 0x........: ... + by 0x........: [EMAIL PROTECTED] (in /lib/libpthread...) + by 0x........: [EMAIL PROTECTED] (tc_intercepts.c:...) + by 0x........: main (tc21_pthonce.c:70) + +Thread #3 was created + at 0x........: clone (in /...libc...) + by 0x........: ... + by 0x........: [EMAIL PROTECTED] (in /lib/libpthread...) + by 0x........: [EMAIL PROTECTED] (tc_intercepts.c:...) + by 0x........: main (tc21_pthonce.c:70) + +Possible data race during write of size 4 at 0x........ + at 0x........: child (tc21_pthonce.c:58) + by 0x........: mythread_wrapper (tc_intercepts.c:...) + by 0x........: ... + by 0x........: ... + Old state: shared-readonly by threads #2, #3 + New state: shared-modified by threads #2, #3 + Reason: this thread, #3, holds no consistent locks + Location 0x........ has never been protected by any lock + +ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) Added: branches/THRCHECK/thrcheck/tests/tc21_pthonce.stdout.exp =================================================================== --- branches/THRCHECK/thrcheck/tests/tc21_pthonce.stdout.exp (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc21_pthonce.stdout.exp 2007-10-30 19:31:43 UTC (rev 7057) @@ -0,0 +1,6 @@ +welcome: Welcome +child: Hi, I'm thread 0 +child: Hi, I'm thread 1 +child: Hi, I'm thread 2 +child: Hi, I'm thread 3 +main: Goodbye Added: branches/THRCHECK/thrcheck/tests/tc21_pthonce.vgtest =================================================================== --- branches/THRCHECK/thrcheck/tests/tc21_pthonce.vgtest (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc21_pthonce.vgtest 2007-10-30 19:31:43 UTC (rev 7057) @@ -0,0 +1 @@ +prog: tc21_pthonce ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Valgrind-developers mailing list Valgrind-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-developers