Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

thread-safe vs async-signal safe

In APUP section 12.5 ,mentioned that:

" If a function is reentrant with respect to multiple threads, we say that it is thread-safe. This doesn't tell us, however, whether the function is reentrant with respect to signal handlers."

I was confusing why a function is thread-safe but maybe not async-signal safe.

is there an example ?

Thanks

like image 826
camino Avatar asked Apr 08 '26 08:04

camino


1 Answers

A function can be made thread-safe by protecting the state it modifies with a mutex. This is, however, not async-signal-safe since if you call the function e.g. from a signal handler the program can deadlock.

A common function with this property is malloc().

like image 54
janneb Avatar answered Apr 10 '26 16:04

janneb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!