- Hands-On Data Structures and Algorithms with Rust
- Claus Matzinger
- 143字
- 2021-07-02 14:11:43
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).
推薦閱讀
- 企業數字化創新引擎:企業級PaaS平臺HZERO
- 數據產品經理高效學習手冊:產品設計、技術常識與機器學習
- Access 2016數據庫教程(微課版·第2版)
- Learning JavaScriptMVC
- 揭秘云計算與大數據
- Proxmox VE超融合集群實踐真傳
- Visual Studio 2013 and .NET 4.5 Expert Cookbook
- Hadoop 3實戰指南
- 數據分析師養成寶典
- Oracle 11g+ASP.NET數據庫系統開發案例教程
- 工業大數據融合體系結構與關鍵技術
- 基于數據發布的隱私保護模型研究
- 反饋:化解不確定性的數字認知論
- SQL必知必會(第5版)
- Getting Started with Review Board