官术网_书友最值得收藏!

Send and Sync

These marker traits are fundamental to Rust's multithreading policies. They have distinct purposes:

  • Send: A data type is safe to send (move) from one thread to the other
  • Sync: The data type can be shared across threads without manual locks or mutex areas

These marker traits are implemented in all basic types of the standard library and can be inherited for custom types (if all properties of a type are Sync, then the type itself is Sync too).

Implementing Sync or Send is unsafe because there is no way for the compiler to know if you are right and the code can be shared/sent between threads, which is why it's very unusual to do this.

In case your program requires this depth of Rust programming, be sure to read up on this topic in the Rust Book, chapter 16 (https://doc.rust-lang.org/1.31.0/book/ch16-04-extensible-concurrency-sync-and-send.html).

主站蜘蛛池模板: 博兴县| 旬邑县| 杭锦后旗| 镇平县| 万荣县| 昭苏县| 广州市| 灌云县| 乐至县| 哈尔滨市| 留坝县| 时尚| 讷河市| 奉新县| 许昌市| 含山县| 长乐市| 贺州市| 托克逊县| 临清市| 武平县| 分宜县| 安远县| 林周县| 桦川县| 枣阳市| 兴化市| 德庆县| 公主岭市| 保靖县| 正定县| 宽城| 乌拉特中旗| 麦盖提县| 巴林左旗| 内丘县| 泰宁县| 微博| 宜兴市| 思南县| 贵阳市|