Sharing data between threads using channels

The idea is to send a piece of information or data of the type T between threads via a channel. Here, T implements the Send trait, which indicates that variables or resources of the type T have the ability to transfer their ownership safely between threads. This particular feature of Rust helps in safe sharing of data between threads. This helps achieve safer concurrency and data-race freedom. The catch here is that the type T, which we want to send across the threads via the channel, must support and implement the Send trait. The second important trait is Sync. When T implements Sync, it means that something of this type has no possibility of introducing memory unsafety when used from multiple threads concurrently through shared references. These two traits allow you to use the Rust type system for making concurrent code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.172.146