thread-safe vs async-signal safe

馋奶兔 提交于 2019-12-08 02:55:35

问题


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


回答1:


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().



来源:https://stackoverflow.com/questions/9512775/thread-safe-vs-async-signal-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!