79827252

Date: 2025-11-22 10:26:49
Score: 0.5
Natty:
Report link

The following code fixes the issue, however when one wants to make it nice maybe use pointers like the comments suggest.

use crossbeam::thread;
use std::cell::Cell;
use std::sync::Arc;
pub struct ThreadCell<T>(pub Cell<T>);
unsafe impl<T> Send for ThreadCell<T> {}
unsafe impl<T> Sync for ThreadCell<T> {}

struct Ship {
    hull: ThreadCell<f32>,
    info: Arc<ShipInfo>,
}
fn shoot(slicea: &[Ship],sliceb: &[Ship]){
// Shooting logic here
}

fn multishoot(slicea: &[Ship],sliceb: &[Ship]){
thread::scope(|s| {
    s.spawn(|_| {
        shoot(slicea, sliceb);
    });
    s.spawn(|_| {
        shoot(sliceb, slicea);
    });
})
.unwrap();
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: basicn00b