liveBook · Manning

Task

As explained in Grokking Concurrency

A task is a logically independent chunk of work that serves as a general abstraction for a unit of execution.

Think of a task as one job in a larger recipe: mixing ingredients, washing a load of laundry, or writing data to a file. A task is a logically independent chunk of work and a general abstraction for a unit of execution. It may contain one operation or a sequence of operations. section 2.2

Programs often execute tasks serially, like washing white clothes, dark clothes, sheets, and towels one load at a time. This ordering is necessary when one task needs the previous task’s result. When tasks are independent, they can instead be organized for concurrent execution. section 2.2 section 2.14

Tasks provide a bridge from an application’s logic to the system that runs it:

  • Task-based programming describes computations without depending on a particular machine and supports modular program construction. section 2.2
  • Concurrency splits a program into tasks that may run in different orders while producing the same result; those units may also be called coroutines, processes, or threads. section 13.1
  • Effective concurrent design first checks whether the problem can be divided into tasks and whether those tasks can communicate and coordinate. section 13.15

From recipe steps to concurrent work

Rotating an image, printing a message, or writing data to a file can each be treated as a task. If several such jobs are independent, a program can organize them for concurrency; if one needs another’s output, their order must be preserved. section 2.2 section 13.1

How Grokking Concurrency covers it

How deep it goes
Defines tasks and contrasts serial, concurrent, and parallel execution, but defers detailed implementation to threads, processes, and runtime systems.
Examples
Uses recipe steps, laundry loads, file writing, image rotation, and screen printing to illustrate task boundaries and dependencies.
What it assumes
Assumes only a basic understanding of programs and instructions while teaching task boundaries, ordering, independence, and coordination from the beginning.
What you can do after
Apply it by decomposing a problem into independent work units and checking their dependencies before choosing serial or concurrent execution.
How it connects
Links tasks to serial execution, concurrency, parallelism, synchronization, threads, processes, coroutines, and runtime systems.

Also explained in

Compare how 10 books explain task →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Concurrency. The section links point to the parts of the book it draws on.