This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][BZ #16159] Detecting that recursive mutex recursed.


Hi,

To fix bugs with malloc async safety I would need a following primitive

int ptrhead_mutex_lock_cnt(pthread_mutex_t *m, int *cnt);

Which works like pthread_mutex_lock except it returns a number of times lock was recursively locked.
This would allow us to detect that function was invoked in signal and provide safe workaround.

In case of malloc we cound fall back to allocating with mmap and filling header that it could be appropriately freed.
A code would lock like this:

if (pthread_mutex_lock_cnt(lock, &cnt)
{
  if (cnt > 0)
    {
      void *ret = mmap (NULL,size, ...
      /* XXX initialize header.  */
      return ret;
    }
}

Comments?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]