Rust concurrency: five easy pieces.

  1. wakes-up when a message is received,
  2. handles the incoming message, and
  3. goes back to blocking on the channel.
  1. the exit confirmation should come as last.

  1. cannot know if the parallel component will exit after the work has been performed.
  1. all work performed by workers has finished.

  1. The parallel component also owns a counter of ongoing work.
  2. Workers on the thread-pool have access to a new channel, which they use to signal to the parallel component when they have completed a unit of work.
  3. The parallel component now selects over two channels: the one for messages from the main component, and the one for messages from workers on the thread-pool.



Further reading

These examples are based on real-world code found in Servo’s net component, in particular how the CoreResourceManager spawns parallel fetch workers on a thread-pool, and how those parallel fetches share an HTTP cache and a corresponding cache state. Please take a look.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store