3 ms·
Who has a signal safe malloc?
by tedunangst 2y ago
Who has a signal safe malloc?
- adrian_b 2y agoPOSIX does not require malloc to be signal safe. Therefore I do not think that anyone has bothered to implement a signal-safe malloc, as this is likely to be complicated. Allocating memory in a signal handler makes no sense in a well designed program, so not being allowed to use malloc and related functions is not a problem.
- tedunangst 2y agoSo it sounds like malloc would be an example of a function which is thread safe but not reentrant.
- skissane 2y agoOn Linux, mmap() is your signal-safe malloc. POSIX doesn't require mmap() to be async-signal safe, but on Linux it de facto is. Of course, doing every memory allocation at the kernel level is going to be very slow and resource intensive. But if it isn't on a hot code path...