O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

GDB - threads

The debuggers can swim in multithreaded programs quite as well as single-threaded ones. Here's the previous program, now doing its calculations in threads:

// broken-program-2/src/main.rs extern crate num; use num::Num; use std::thread; use std::sync::{Arc, Mutex}; fn multiply_and_store<N: Num + Copy + Send>(nums: Arc<Mutex<Vec<N>>>, num: N, multiplier: N) {     let mut data = nums.lock().unwrap();     data.push(num * multiplier); } fn multiply_numbers_by<N: 'static + Num + Copy + Send>(nums: Vec<N>, multiplier: N, ret: Arc<Mutex<Vec<N>>>) {     let mut threads = vec!();     for num in nums {         let ret = ret.clone();         threads.push(thread::spawn(move || {             multiply_and_store(ret, num, multiplier);         }));     }     for thread in threads {  let _ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required