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

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

主站蜘蛛池模板: 什邡市| 定兴县| 中宁县| 陇南市| 南开区| 玉屏| 龙胜| 全南县| 新绛县| 象州县| 台州市| 金门县| 大化| 滁州市| 大港区| 玛纳斯县| 岳池县| 牟定县| 漳浦县| 内江市| 嘉祥县| 涟源市| 西城区| 大名县| 乐至县| 四川省| 大关县| 四会市| 舒城县| 英超| 金塔县| 那坡县| 惠水县| 泉州市| 科技| 探索| 海盐县| 迁安市| 奎屯市| 沧源| 吉水县|