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.