- 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).
推薦閱讀
- 數據可視化:從小白到數據工程師的成長之路
- Word 2010中文版完全自學手冊
- 從零開始學Hadoop大數據分析(視頻教學版)
- 使用GitOps實現Kubernetes的持續部署:模式、流程及工具
- 大數據可視化
- Game Development with Swift
- 正則表達式必知必會
- Access 2007數據庫應用上機指導與練習
- 區塊鏈通俗讀本
- 數據革命:大數據價值實現方法、技術與案例
- Python數據分析與數據化運營
- Deep Learning with R for Beginners
- 信息融合中估計算法的性能評估
- 從Lucene到Elasticsearch:全文檢索實戰
- 標簽類目體系:面向業務的數據資產設計方法論