FlashKeepers

Rust · College · College and University

Rust V: Concurrency and Async

Threads, channels, Mutex, Arc, Send and Sync, async and await, futures and tokio basics.

About this set

34 basic cards for College Rust. Set 5 of 6 in Rust. It opens with "What does thread::spawn return?" and "What does JoinHandle::join() do?". Study it alongside the other College sets below.

34 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does thread::spawn return?
Show answerJoinHandle<T>
What does JoinHandle::join() do?
Show answerBlocks until the thread completes and returns Result<T, E>
What trait must a closure passed to thread::spawn implement?
Show answerSend + 'static
What is Arc?
Show answerAtomic Reference Counting, a thread-safe shared ownership pointer
When should you use Arc instead of Rc?
Show answerWhen sharing data across multiple threads
What does Arc::clone() do?
Show answerIncrements the reference count and returns another Arc to the same data
What is Mutex?
Show answerA lock ensuring only one thread can access the protected data at a time
What does Mutex::lock() return?
Show answerResult<MutexGuard<T>>
What is MutexGuard?
Show answerAn RAII guard that holds the lock until it is dropped
What is the Send trait?
Show answerA marker trait indicating a type is safe to transfer ownership between threads
What is the Sync trait?
Show answerA marker trait indicating a type is safe to share &T references between threads
Are all Send types also Sync?
Show answerNo, Send and Sync are independent traits
What is RwLock?
Show answerA lock allowing multiple concurrent readers or one exclusive writer
When should you prefer RwLock over Mutex?
Show answerWhen you have many readers and few writers
What does mpsc::channel() return?
Show answer(Sender<T>, Receiver<T>)

19 more cards in the app

Study this set free