Preliminary. ThinkMeta ConcurrentTasks and this documentation are preliminary; everything is subject to change.

Samples

Each sample is a complete console program: it creates its own scheduler, its own input files or network peers, checks its results and cleans up after itself. Every sample on these pages is compiled and run against the current API, so the code you read is the code that works.

All samples

Sample What it shows
Hello task The smallest program: a scheduler, one task, a wait, a clean shutdown.
Ping-pong Two tasks hand the processor back and forth through two semaphores; round trips per second.
Wait for a group Fork/join: hundreds of short tasks summing an array, joined with a reusable task group.
Producer/consumer Work items through a bounded lock-free queue, counted by semaphores, sized so it cannot overflow.
Timeouts Waits with a time limit, sleeping tasks, tasks started by time and a cancelled start.
Async file copy Overlapped reads and writes from a task, with the next read running while the current block is written.
Hashing A file streamed through a zero-copy pipe into a SHA-256 hash while it is still being read.
Ordered output A file of records built front to back: deferred copies by copy tasks, writing by a writer task.
TCP echo server A listening socket, one task per connection, and clients in the same program that check the echo.

To build a sample, set up a project as described in Set up a project and add the sample's .cpp file. Some samples need an extra Windows library; their pages say which.

Real-world task graphs

The samples are small on purpose. Larger programs built on ConcurrentTasks show how the same building blocks scale to complete task graphs – readers, encoders and writers running as many tasks that wait on each other, on files and on memory pipes:

  • ctLame – an MP3 encoder that writes the same files as LAME.
  • ctJpeg – a JPEG encoder that writes the same files as jpegli.
  • ctOpus – an Opus encoder that writes the same files as opusenc.
  • ctDeflate – a gzip compressor that writes the same files as libdeflate's gzip.

Each page tells how its task graph evolved and what it gained.

Their sources and further samples are in the ThinkMeta.ConcurrentTasks.Samples repository on GitHub. The Task graphs guide explains the patterns they use.