Re: Memory Fragmentation - Weekly Report



Hi,

On Mon, 2008-06-02 at 13:41 +0300, Andrei Soare wrote:
> 
> - the first one is here:
> http://mail.gnome.org/archives/gnome-love/2008-May/msg00037.html

Use pthread_mutex_lock/unlock().  You need to declare a global mutex:

#include <pthread.h>

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

Then make sure only one thread is in your overriden functions at a time.

my_malloc(...)
{

  pthread_mutex_lock (&mutex);

  install old hooks...
  malloc...
  install my hooks again...

  pthread_mutex_unlock (&mutex);

  return...
}


Hope that helps.

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]