[plug] crashing server

James Devenish devenish at guild.uwa.edu.au
Wed Sep 15 08:36:58 WST 2004


Hi,

You are right that this should not bring down the machine. However:

In message <16711.33711.592237.491232 at pride.nsw.cmis.CSIRO.AU>
on Wed, Sep 15, 2004 at 09:50:07AM +1000, Rob Dunne wrote:
> The description of the code (dotprod_mutex.c)
> /*****************************************************************************
>  * FILE: dotprod_mutex.c
[...]
>  * SOURCE: Vijay Sonnad, IBM
>  * LAST REVISED: 9/20/98 Blaise Barney

I found the file with Google and noted the following lines of code:

    double *a, *b;
    a = (double*) malloc (NUMTHRDS*VECLEN*sizeof(double));
    b = (double*) malloc (NUMTHRDS*VECLEN*sizeof(double));
    a[i]=1;
    b[i]=a[i];
    free (a);
    free (b);

Notes:
(1) The code contains no validation of a or b -- what if the allocation
failed? (Extremely unlikely, but theoretically possible. It would be
expected to cause a crash much earlier than you have indicated.)

(2) The code contains the following execution:
    pthread_create( &callThd[i], &attr, dotprod, (void *)i); 
Where:
    void *dotprod(void *arg) {
        ...
        int offset = (int)arg;
        ...
    }
This abuse of pointer storage and arithmetic storage (casting an int as
a pointer and a pointer as an int) is rude and, IIRC, behaviour is not
defined in standard C.

(3) As a really basic check: can you set your coredumpsize to zero (to
prevent bringing down the machine) and then add the following to various
parts of the code:

printf( "%d -- a: %p; b: %p;\n", __LINE__, a, b );

Then, check that a and b are stable throughout the programme.

(4) Is it ever possible for the b=malloc(int)...b[i] motif to fail if
there is some CPU data alignment restriction?





More information about the plug mailing list