Share Rust Thread Data With Mutexes 🦀 Rust Tutorial

preview_player
Показать описание
Rust threads can share access to memory by using a Mutex (mutual exclusion). The Mutex structure is built into the Rust standard library, and can be used to temporarily lock exclusive access to a value, from a thread. Because Mutexes have the single-lock guarantee, many Rust threads can access the same data safely. In this video, we take a hands-on look at how Mutexes work, and how to write code from scratch, using them! 🦀

Please follow me on these other social channels!

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement.

#rustlang #rust #rustdev #opensource #software #linux #devops #programming #rusty #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #developer
Рекомендации по теме
Комментарии
Автор

I really really appreciate your videos :)))) helped me get closer to finishing my projects

nation
Автор

It might have been nice to mention that the best practice is to lock the mutex (or any kind of lock) for as little time as possible. Putting the lock() call and (omg, really, no unlock yet?) drop() on either side of the add_assign() inside the loop would, theoretically lock and unlock the mutex during each loop and give control back and forth as quickly as possible. Otherwise, great content, and thanks for making the topic accessible!

christopherpetersen
Автор

Thanks for the video. I have a hard time learning from just text so it helps a lot to have a voice to the material.

Mudclippa
Автор

excellent contents for rust, thanks sir.

JIeFu-eexk
Автор

Cool, was confused a bit while reading the book, but things made clearer here. So in the book, they have used Arc<Mutex<T>> so share and update the data between the threads. In this video we have used "thread::scope" to share Mutex<T> across threads and modify the data inside. So what I've understood is there are two ways we can reference the data from the main thread inside the spawned thread and then alter it inside the spawned thread.

So what might be the differences between these approaches?. Like when to use Arc<T> to share the data across the threads or when to use thread::scope to share the data?

Qwerty-ofox
Автор

man i really thank you from my hear for these videos... finally i found someone that can explains rust with a simple way that i can understand

AhmedFalih-kjtt
Автор

Thank you for your efforts really appreciate the clear voice and explanation and efforts put in the video

mryoutuser
Автор

wouldnt you just derefence the MutexGuard to work with the data? is there some benefit to working with the MutexGuard's methods instead of derefencing it?

irlshrek
Автор

Demo of join part is not doing what you think. The second thread never runs concurrently, join forces it to run now.
Test wirh lock/unlock inside loop to show thread working concurrently.

MathewBoorman
Автор

how about std::sync::mpsc ... is it an advance topic?

AhmedFalih-kjtt
join shbcf.ru