# Simple generic parallelism idiom & C++17 specifics

DevFeed: [Simple generic parallelism idiom & C++17 specifics](<https://devfeed.tech/articles/simple-generic-parallelism-idiom-c-17-specifics-36539.md>)

Original publisher: [Read original article](<https://berthub.eu/articles/posts/simple-parallelism-idiom/>)

Published: 2022-01-18T10:52:00Z

Content type: tutorial

Language: en

Sources: [Bert Hubert's writings](<https://devfeed.tech/sources/bert-hubert-s-writings.md>)

Topics: [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Concurrent Programming](<https://devfeed.tech/topics/concurrent-programming.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [compiler](<https://devfeed.tech/tags/compiler.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [parallelism](<https://devfeed.tech/tags/parallelism.md>), [programming](<https://devfeed.tech/tags/programming.md>), [threads](<https://devfeed.tech/tags/threads.md>), [ubuntu](<https://devfeed.tech/tags/ubuntu.md>)

## AI overview

This article presents a simple parallelism idiom for distributing work across multiple threads using an atomic counter. It also discusses the corresponding C++17 primitives and practical caveats, including behavior observed with GCC 11.2.0 on Ubuntu.

## Source excerpt

If you programmed something and it turns out to be too slow, often you'd like to farm out the work to multiple threads. At this point you typically have a few choices: use some kind of producer/consumer pipe half-ass it by dividing the work into n chunks and launch n threads and hope for the best rely on one of the magic parallelization solutions (#pragma omp) use (newfangled) language features All of these options are painful to some extent.