- 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).
推薦閱讀
- Python絕技:運(yùn)用Python成為頂級(jí)數(shù)據(jù)工程師
- 使用GitOps實(shí)現(xiàn)Kubernetes的持續(xù)部署:模式、流程及工具
- UDK iOS Game Development Beginner's Guide
- 大數(shù)據(jù)營(yíng)銷:如何讓營(yíng)銷更具吸引力
- 深入淺出Greenplum分布式數(shù)據(jù)庫(kù):原理、架構(gòu)和代碼分析
- R語(yǔ)言數(shù)據(jù)挖掘
- 云數(shù)據(jù)中心網(wǎng)絡(luò)與SDN:技術(shù)架構(gòu)與實(shí)現(xiàn)
- Splunk智能運(yùn)維實(shí)戰(zhàn)
- 區(qū)域云計(jì)算和大數(shù)據(jù)產(chǎn)業(yè)發(fā)展:浙江樣板
- 活用數(shù)據(jù):驅(qū)動(dòng)業(yè)務(wù)的數(shù)據(jù)分析實(shí)戰(zhàn)
- Doris實(shí)時(shí)數(shù)倉(cāng)實(shí)戰(zhàn)
- 智慧城市中的大數(shù)據(jù)分析技術(shù)
- 大數(shù)據(jù)與機(jī)器學(xué)習(xí):實(shí)踐方法與行業(yè)案例
- Access 2016數(shù)據(jù)庫(kù)應(yīng)用基礎(chǔ)
- Access 2013 數(shù)據(jù)庫(kù)管理與應(yīng)用從新手到高手