__try/__finally equivalent in UNIX

99封情书 提交于 2020-01-06 15:52:27

问题


I have a library that written mostly in C, Some parts of it should be thread safe and I use global spinlock to protect the critical section of the code.

Now my problem is:
I should call some callback of the user from inside of a critical section that protected by a spinlock and in case that those callbacks generate an exception, on Windows I have a _try/_finally in C to be able to leave the critical section even when an error occurred. Can I accomplish this on UNIX too?


回答1:


This is called structured exception handling. It can be accomplished by using setjmp and longjmp. It has been used in C for a long time. See this for details: http://www.freetype.org/david/reliable-c.html



来源:https://stackoverflow.com/questions/13001786/try-finally-equivalent-in-unix

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