Concurrency 线程生存期错误

Concurrency 线程生存期错误,concurrency,rust,lifetime,Concurrency,Rust,Lifetime,我正在尝试使用Rust中的并发实现游戏“河内之塔”。老实说,上一次我试着理解锈迹斑斑的一生,但我还没有完全理解。这就是为什么我会犯一些奇怪的终身错误,我不明白。首先,这里是一段重要的代码 fn move_plate<'a>(stack_a: &'a mut Vec<i32>, stack_b: &'a mut Vec<i32>, stack_c: &'a mut Vec<i32>, moves: &'a m

我正在尝试使用Rust中的并发实现游戏“河内之塔”。老实说,上一次我试着理解锈迹斑斑的一生,但我还没有完全理解。这就是为什么我会犯一些奇怪的终身错误,我不明白。首先,这里是一段重要的代码

fn move_plate<'a>(stack_a: &'a mut Vec<i32>, stack_b: &'a mut Vec<i32>, 
    stack_c: &'a mut Vec<i32>, moves: &'a mut Vec<(i32, i32)>) 
{
        let mut moves1: Vec<(i32, i32)> = Vec::new();
        let guard1 = Thread::scoped(
            move || { move_plate(stack_a, stack_c, stack_b, (1, 3, 2), &mut moves1); 
        });
        guard1.join().ok();
}
我知道我必须避免线程,以使其比函数更长寿,因为否则对移动的引用就会消失。但是既然我加入了线程,那应该没问题,不是吗?在那一点上我遗漏了什么?
如果有人能帮我,那就太好了,我只是习惯了那种很酷(但很复杂)的东西

这是已知的锈型系统的局限性。当前,Rust仅允许在该数据满足
send
绑定的情况下在线程之间发送数据,
send
意味着
'静态
——也就是说,可以跨线程边界发送的唯一引用是
'静态
引用

有一种方法部分解除了这一限制,允许跨任务发送非静态引用。我以为它已经被接受了,但事实并非如此(这很奇怪)。支持这种东西的API已经创建(这可能是您感到困惑的原因),但是语言还没有调整

error: cannot infer an appropriate lifetime due to conflicting requirements
    let guard1 = Thread::scoped(move || {
                     move_plate(height - 1, stack_a, stack_c, stack_b, (1, 3, 2), threads, depth + 1, &mut moves1);
                 });
note: first, the lifetime cannot outlive the expression at 93:25...
             let guard1 = Thread::scoped(move || {

note: ...so that the declared lifetime parameter bounds are satisfied
             let guard1 = Thread::scoped(move || {

note: but, the lifetime must be valid for the expression at 93:45...
             let guard1 = Thread::scoped(move || {
                 move_plate(height - 1, stack_a, stack_c, stack_b, (1, 3, 2), threads, depth + 1, &mut moves1);
             });
note: ...so type `closure[]` of expression is valid during the expression
             let guard1 = Thread::scoped(move || {
                 move_plate(height - 1, stack_a, stack_c, stack_b, (1, 3, 2), threads, depth + 1, &mut moves1);
             });
error: declared lifetime bound not satisfied
             let guard1 = Thread::scoped(move || {