liveBook · Manning

Work queue pattern

As explained in Rust in Action: Systems programming concepts and techniques

A task queue is a pattern in which tasks are submitted independently of their processing and are later retrieved by worker threads.

A work queue separates task creation from task processing. Tasks can originate anywhere, wait in a channel, and then be retrieved by worker threads when those workers are ready. section 10.4.4

A channel-based queue provides the main moving parts:

  • A sending end accepts multiple tasks, even when the receiver is temporarily busy. section 10.4.4
  • A receiving end delivers tasks to worker threads through recv(). section 10.4.4
  • Arc<Mutex<T>> can protect shared task or result vectors, but channels offer a simpler alternative. section 10.4.4

Rendering work with two threads

A render-hex program defines Work::Task and Work::Finished, creates an unbounded crossbeam channel, parses input into operations, and configures two worker threads to process queued work.

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Explains shared-memory locking and channel endpoints, then demonstrates sending, receiving, worker loops, and task messages.
Examples
Uses integer messages, ping-pong connectivity checks, and a render-hex queue containing Task and Finished messages.
What it assumes
Introduces synchronization through shared vectors, Mutex, Arc, channels, send(), and recv() while assuming basic Rust thread usage.
What you can do after
Build it from scratch with crossbeam channels and spawned Rust threads to route work and responses.
How it connects
Connects work queues with worker threads, thread pools, channels, mutexes, atomic reference counting, and message passing.

Also explained in

Compare how 4 books explain work queue pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.