How to send data to named thread

I want to do like that, I create some threads, eg. t1,t2,t3,t4;
idle threads list, idles=[t2,t3,t4]
a new job comes, so I want send the job to the threads in idles.
when a thread is free, it will add to the idles.
thread::spawn(move || loop {})
It's like a bunch of guys playing football.

You can create an mpsc channel to send data from one thread to another. You simply move the receiver into the spawned closure, and receive items through it. If you need more than one receiver per channel, or some other advanced features, take look at the crossbeam crate which has more powerful channels.

I expect this is a placeholder, but beware, LLVM currently marks such loops unreachable for lack of forward progress -- see

Thanks a lot.

Just out of curiosity, are you trying to implement a threadpool? If so, you may want to have a skim
through the source code for the threadpool crate on GitHub.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.