just::thread C++11 and C++14 Thread Library V2.0 released

just::thread 2.0 is now available.

Anthony Williams' implementation of the C++11 and C++14 threading library adds support for gcc 4.8 and Microsoft Visual Studio 2013 and with a number of new features.

just::thread now includes:

  • The new std::shared_timed_mutex and std::shared_lock from C++14 allow for multiple readers to hold a shared lock on a mutex or one writer to hold an exclusive lock.

  • The extensions to the futures from the upcoming C++ Concurrency Technical Specification in the form of continuations. std::future<> and std::shared_future<> now have an additional member function "then()" which allows a further task to be scheduled when the future becomes "ready". This allows for improved support for asynchronous tasks.

  • jss::when_any and jss::when_all encapsulate a set of futures into a single future which becomes ready when either one or all of the provided futures becomes ready. This can be used with continuations to schedule asynchronous tasks to run when the prerequisites are ready.

  • A new lock wrapper jss::generic_lock_guard is provided. This is a concrete type rather than a template, and will lock any type of mutex which provides lock and unlock member functions.

Very Strong C++ Track at the NDC Conference [June 2-6, Oslo, Norway] -- Anders Schau Knatten

A useful reminder:

Very Strong C++ Track at the NDC Conference [June 2-6, Oslo, Norway]

by Anders Schau Knatten

From the article:

... there’ll be no less than 13 talks, by Nico Josuttis, Scott Meyers, Andrei Alexandrescu, Hubert Matthews, Mike Long, Isak Styf, Ismail Pazarbasi, Olve Maudal, and myself. In addition, Andrei Alexandrescu will give a two day workshop. Here’s the full list:

Stopping the Spew -- Tony DaSilva

Today on Bulldozer00:

Stopping the Spew!

by Tony DaSilva

From the article:

Every C++ programmer has experienced at least one, and most probably many, “Template Spew” (TS) moments. You know you’ve triggered a TS moment when, just after hitting the compile button on a program the compiler deems TS-worthy, you helplessly watch an undecipherable avalanche of error messages zoom down your screen at the speed of light. ...

... Fear not, because help is on the way via C++14 in the form of "concepts lite".

Quick Q: How do generic lambdas work? -- StackOverflow

Quick A: They generate a templated operator(), and that means you can call the same closure object with all sorts of different parameters and it just stamps out the function for each set of parameter types.

A "new classic" question on SO, classic because it was posted a year ago, but newly relevant because now the mainstream compilers are implementing the feature:

How does generic lambda work in C++14?

How does generic lambda work (auto keyword as argument type)?

Is it similar to templates where for each different argument type compiler generates functions with the same body but changed types or is it more similar to Java's generics?

Code example:

auto glambda = [](auto a) { return a; };

Fast Polymorphic Collections with Devirtualization -- Joaquín M López Muñoz

munoz.pngStill on the theme of "contiguous enables fast," a followup on the recent "Fast Polymorphic Collections" article:

Fast Polymorphic Collections with Devirtualization

by Joaquín M López Muñoz

From the article:

The poly_collection template class we implemented for fast handling of polymorphic objects can be potentially speeded up in the case where some of the derived classes it manages are known to the compiler at the point of template instantiation...

Allowing for the specification of a list of statically known derived class types as part of a poly_collection instantiation opens up possibilities for internal performance optimizations that do not impact the usage interface of this template class. The actual improvements achieved depend very much on the compiler being used, but in general are greater when passing polymorphic functors (such as generic lambdas) to for_each and qualifying virtual functions as final where possible.

Introducing emplacer -- Tim

Another nice way to have a polymorphic collection without sacrificing that performance-precious contiguous memory layout:

Introducing emplacer: allocate subtypes of an abstract base class directly in a container

by Tim

From the article:

So I complained to my friend Jeremy that C++ should be able to do this. This isn't Java, I shouldn't have to do a separate allocation for each object...

As alluded to earlier, you can also use it in containers. Here's an example:

std::vector<ShapeAny> shapes;

shapes.emplace(shapes.end())->emplace<Rect>(3, 4);
shapes.emplace(shapes.end())->emplace<Square>(3);

//emplace returns reference to *this, so you can use it like this too
shapes.push_back(ShapeAny().emplace<Rect>(5, 6));
shapes.push_back(ShapeAny().emplace<Circle>(1));

for (auto shape: shapes) {
  std::cout << shape->area() << std::endl;
}