我有一个启动工作线程的线程,所有线程都有望永远存在。每个辅助线程都维护自己的Socket
s 列表。
某些操作要求我遍历当前存在的所有套接字,但是在尝试创建一个包含指向另一个列表所拥有的套接字的指针的套接字主列表时,我遇到了麻烦。
我收到的错误...
error[E0477]: the type `[closure@src/main.rs:107:34: 107:86 tx:std::sync::mpsc::Sender<std::net::TcpStream>, rx:std::sync::mpsc::Receiver<std::net::TcpStream>, master_socket_list:std::sync::Arc<std::sync::Mutex<mastersocketlist::MasterSocketList<'_>>>]` does not fulfill the required lifetime
--> src/main.rs:107:20
|
107 | let prox = thread::spawn(move || Slot::event_loop(tx, rx, master_socket_list));
| ^^^^^^^^^^^^^
|
= note: type must outlive the static lifetime
我什至不知道我要尝试的代码是否可以作为安全代码。
我希望mastersocketlist包含指向套接字的指针,其中套接字的生存期由创建它的线程定义。我相信这就是所有这些错误的含义,但是我不知道如何提供适当的生命周期注释来修复它。
相关分类