Seems there is no native WORK QUEUE?

It seems there is no native support for something like multi-thread-safe work queue, such as blocking queue or concurrent queue in other languages. Work queue is very important to the users in writing some Event Drive code , PUB/SUB mode or something like Job Dispatch procedures.

Requests is very simple: Let users to decide whether BLOCK the consumer or not, and Let users to decide HOW MANY Threads should WAIT for the incoming job, and Let users to decide HOW MANY job dispatchers in the system.

After checking the Channel(SPSC, MPSC, or Broadcast) and some Tokio things look similar to the standard lib, I am so confused how to realize a WORK QUEUE by these Channel things? Manually park or unpark the job consumer thread with future things? Building 2 channels between job dispatcher and the actual worker thread? How can I realize the thread competition?

Is there any solution or stable crate?

The crossbeam channel is currently the most powerful channel implementation. It supports multiple senders and receivers, and allows selection.

You may also want to look into crates that provide some sort of threadpool. The threadpool crate provides a rather straight-forward threadpool. The rayon crate provides a pretty interesting thread pool with various tools for iterators and joining tasks, and tokio provides a threadpool for tasks that are IO bound rather than CPU bound.

2 Likes

Thanks a lot! I think crossbeam crate can solve the problem!

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