Difference between thread safe and async-signal safe

╄→гoц情女王★ 提交于 2019-12-04 03:38:47

Q1: async-signal safe is the strongest concept of reentrancy. It requires very careful use of resources and is hard to manage in cross-platform application code.

Q2: async-signal safe implies thread safe. Thread safe means it's OK to try calling the function twice, but from different threads; async-signal safe is stronger because two invocations of the function can be in the same thread. This makes things much harder, because you can't simply wait for the other invocation of the function to release its locks, the second call inside the signal handler has to be able to interrupt the first one even if shared resources are in an inconsistent state, then restore things when it exits. It's basically impossible to use shared resources/state from a signal handler: always use the "self-pipe trick" unless you really know how signal handlers work and have some obscure reason for writing insane code.

Q3: some people may use reentrant to mean just thread safe. Unix signal handlers are the only common place where anything stronger is needed, and that's a bit obscure because you shouldn't be trying to do anything clever there.

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