sftrabbit / CppPatterns-Patterns

A repository of modern C++ patterns curated by the community.
Creative Commons Zero v1.0 Universal
1.43k stars 223 forks source link

Added a concurrency section, with examples #61

Closed DarkerStar closed 8 years ago

DarkerStar commented 8 years ago

I thought concurrency was a big enough topic that it deserved its own section. Included are six examples:

sftrabbit commented 8 years ago

Wow - a whole bunch of samples. Great! I'll be catching up on updating the site this coming weekend, so I'll take a look then. Thanks.

sftrabbit commented 8 years ago

Thanks for the great samples and for creating the much needed concurrency section! I've actually cut it down to just 3 samples for the following reasons:

  1. We can cover passing arguments to a thread in the same sample as creating the thread. They're practically tied together.
  2. I don't think we should be providing implementation of data types like the thread-safe queue - that's more what libraries are for! The samples should just demonstrate how to solve simple, common tasks with the core language and library.
  3. Having a std::lock sample would be very useful, but I felt like your multiple locks one was overcomplicated. If you want to have a go at writing a simpler one, please go ahead! Remember that samples should demonstrate one simple thing and not focus on specific examples (that's why I called the site C++ samples, not C++ examples).

Other than that, I just did a bit of tidying up, rewording, and simplifying some things. Once again, thanks for the contribution!

DarkerStar commented 8 years ago

All good points!

I'll make a new std::lock example that focuses on the actual locking without any extra cruft.

I'll also make a simpler, more focused sample for std::mutex, and maybe something atomic (which will possibly be the same sample), and I'll think of something for condition variables, too.