title: Pushing data back upstream from thread
body: <p>I'm completely open to any and all critiques. I'm completely new to multi-threading and the docs don't make much sense to me.</p>
  <p>The code provided is min-reproducible. The matrix I'm using is much more elaborate, but this works. The point is to use a global process for various vectors within the structs concurrently, then push all the data upstream and back into the global.</p>
  <p>I'm receiving an error at line 59 the first <code>unwrap()</code>. Is there a better way to approach this problem altogether???</p>
  <pre><code>use std::{
      sync::mpsc::channel,
      sync::{Arc, Mutex},
      thread,
  };
  
  #[derive(Debug, Clone)]
  struct Data {
      block: Vec&lt;List&gt;,
  }
  #[derive(Debug, Clone)]
  struct List {
      multiplier: f64,
      num: f64,
  }
  
  static mut IterationData: Data = Data { block: Vec::new() };
  
  const N: u128 = 100;
  
  fn main() {
      unsafe {
          for n in 0..N {
              let mut number = 0.0;
  
              let list = List {
                  multiplier: n as f64,
                  num: 1.0,
              };
  
              IterationData.block.push(list);
          }
  
          let mut data = Arc::new(Mutex::new(IterationData.clone()));
          let (tx, rx) = channel();
          for n in 0..IterationData.block.len() {
              let (data, tx) = (Arc::clone(&amp;data), tx.clone());
              thread::spawn(move || {
                  let mut data = data.lock().unwrap();
  
                  let mut data_2 = Arc::new(Mutex::new(IterationData.block[n].clone()));
                  let (t, r) = channel();
                  for m in 0..IterationData.block.len() {
                      let (data_2, t) = (Arc::clone(&amp;data_2), t.clone());
                      thread::spawn(move || {
                          let mut data_2 = data_2.lock().unwrap();
  
                          data_2.num += N as f64;
  
                          if m + 1 == IterationData.block.len() {
                              t.send(()).unwrap();
                          }
                      });
                  }
  
                  r.recv().unwrap();
  
                  let test_2 = Arc::try_unwrap(data_2).unwrap().into_inner().unwrap();
  
                  data.block[n] = test_2;
  
                  if n + 1 == IterationData.block.len() {
                      tx.send(()).unwrap();
                  }
              });
          }
  
          rx.recv().unwrap();
  
          let test_1 = Arc::try_unwrap(data).unwrap().into_inner().unwrap();
  
          IterationData = test_1;
      }
  }
  </code></pre>