multithreading - Are all built-in functions thread safe? - Stack Overflow

In C some inbuilt functions are not thread safe and there exists a thread safe alternative for such not

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?

Share Improve this question edited Mar 12 at 17:46 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 12 at 17:26 HarryHarry 3,2581 gold badge24 silver badges46 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 7

If 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744736693a4590792.html

相关推荐

  • multithreading - Are all built-in functions thread safe? - Stack Overflow

    In C some inbuilt functions are not thread safe and there exists a thread safe alternative for such not

    7天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信