tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: pthread free() weirdness with cxx
@ 2001-04-30  8:46 Michael Haller
  0 siblings, 0 replies; only message in thread
From: Michael Haller @ 2001-04-30  8:46 UTC (permalink / raw)
  To: tru64-unix-managers

Better late then never...

Original question follows.  Thanks to Thomas Blinn
and John Reguera.

Hi Michael,
  We believe that we have a resolution for you.

What was happening with your reproducer is:

the application allocates approx 50,000 items of approx,
the same size, then free's every other element - which resulted
in a free list of 25k elements.

What malloc/libc does, and it seems to work in "most cases"
is create a singly linked list

Luckily, libc/malloc engineering had the wisdom to allow the end
user to implement a doubly linked list. This will solve your
performace
issue.

Please add the following line of code to your source:

const extern int __fast_free_max = 14;

If this is an unacceptable solution, Please feel free to open an
IPMT case through your normal support channels against
LIBC/Malloc.


thanks

John Reguera
DecThreads Support Engineering
************************************************

--------------- <ORIGINAL QUERY> -----------------------------

Hi,

System is OSF1 V5.1 732 alpha.
Compaq C++ V6.2-024 for Compaq Tru64 UNIX V5.1 (Rev. 732)

There seems to be a strange problem with C++ programs
compiled with the -pthread flag.

Example program:

#include <stdio.h>
#include <stdlib.h>

#define MAXSIZE 24795
#define MALSIZE1 32
#define MALSIZE2 20

int main() {
    char *blah, *blah2;
    char  *index[MAXSIZE], *index2[MAXSIZE];  

    for (int k=0; k<MAXSIZE; k++) {
        static int bla;
        blah = new char[MALSIZE1];
        sprintf (blah, "bla%d", ++bla);
        index[k] =  (char*) blah;
        blah2 = new char[MALSIZE1];
        sprintf (blah2, "bla%d", ++bla);
        index2[k] =  (char*) blah2;
    }
    printf("blah\n");

    for (int k=0; k<MAXSIZE; k++) {
        delete [] index[k];
    }
    printf("blah 1\n");

    for (int k=0; k<MAXSIZE; k++) {
        delete [] index2[k];
    }
    printf("blah 2\n");
}


Runs very fast when compiled:

    cxx t.cc

and very slow (5 seconds) if compiled:

    cxx t.cc -pthread

Further tests....

1. If I move the second delete statement into the first
delete loop the execution speed is effectively the same with or
without the -pthread flag.

2. If I alloc MALSIZE2 into index2 and MALSIZE1 into index1
excution speed is effectively the same with or without the
-pthread flag...irrespective of where index2 is deleted.

Has this problem been seen before?  Can anybody reproduce
it locally?  Is there a solution?

Many thanks for any help or advice,

        - Michael

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-04-30  8:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-04-30  8:46 SUMMARY: pthread free() weirdness with cxx Michael Haller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox