admin管理员组文章数量:1391805
In C
some inbuilt functions are not thread safe and there exists a thread safe alternative for such not thread safe functions.
For example: locatime
is not thread safe, the thread safe alternative is localtime_r
.
So, similarly in Rust
, do we have such kind of thing (thread safe version and not thread safe versions). Or, is it guaranteed that all built-in functions are thread safe?
In C
some inbuilt functions are not thread safe and there exists a thread safe alternative for such not thread safe functions.
For example: locatime
is not thread safe, the thread safe alternative is localtime_r
.
So, similarly in Rust
, do we have such kind of thing (thread safe version and not thread safe versions). Or, is it guaranteed that all built-in functions are thread safe?
1 Answer
Reset to default 7If a free function is not thread-safe it will (or should) be marked unsafe
with the safety criteria documented. One example from the standard library is std::env::set_var
.
I do not know of any Rust built-in functions that are not thread-safe by choice, rather as a reflection of external choices (like environment variables above). Historically non-thread-safe functions have been a source of confusion and error (even set_var
if you look into its history) - thus they are avoided and guarded against in Rust.
本文标签: multithreadingAre all builtin functions thread safeStack Overflow
版权声明:本文标题:multithreading - Are all built-in functions thread safe? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744736693a2622374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论