我有一個啟動工作線程的線程,所有線程都有望永遠存在。每個輔助線程都維護自己的Sockets 列表。某些操作要求我遍歷當前存在的所有套接字,但是在嘗試創建一個包含指向另一個列表所擁有的套接字的指針的套接字主列表時,我遇到了麻煩。我收到的錯誤...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包含指向套接字的指針,其中套接字的生存期由創建它的線程定義。我相信這就是所有這些錯誤的含義,但是我不知道如何提供適當的生命周期注釋來修復它。
- 1 回答
- 0 關注
- 876 瀏覽
添加回答
舉報
0/150
提交
取消