我有一個(gè)啟動(dòng)工作線程的線程,所有線程都有望永遠(yuǎn)存在。每個(gè)輔助線程都維護(hù)自己的Sockets 列表。某些操作要求我遍歷當(dāng)前存在的所有套接字,但是在嘗試創(chuàng)建一個(gè)包含指向另一個(gè)列表所擁有的套接字的指針的套接字主列表時(shí),我遇到了麻煩。我收到的錯(cuò)誤...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包含指向套接字的指針,其中套接字的生存期由創(chuàng)建它的線程定義。我相信這就是所有這些錯(cuò)誤的含義,但是我不知道如何提供適當(dāng)?shù)纳芷谧⑨寔硇迯?fù)它。
- 1 回答
- 0 關(guān)注
- 883 瀏覽
添加回答
舉報(bào)
0/150
提交
取消