how can i know whether a linux syscall is thread safe?

假如想象 提交于 2019-12-06 14:19:58

问题


some functions in linux mark "thread safe" by _r (e.g. gmtime_r ) but most of the syscalls are not be marked and also not mentioned in manpages. So my question is : How can i konw whether a linux syscall is thread safe? Thank you!


回答1:


I think you mean "library functions"; syscalls should, by virtue of operating on the thread's kernel-side data, be thread-safe.

And the answer is: check the manual pages for the functions in question. The "_r" variants are provided specifically for functions which were non-reentrant, meaning that the extra parameters passed to them were statically declared and modified in the non-"_r" versions.

Most of glibc should be, IIRC, thread-safe, but you always need to check manual pages; or, if you don't trust those, the code itself. There's no silver bullet that will remove from you the responsibility of understanding the interfaces which you are programming against.



来源:https://stackoverflow.com/questions/12025640/how-can-i-know-whether-a-linux-syscall-is-thread-safe

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