Concurrent object wrapper – C++11 – Part II

In a previous post I presented an implementation of a concurrent object wrapper. In this post, the implementation is extended to deal with one obvious short-coming of the original: the lack of a means to return values from the actions passed to the wrapper.



Concurrent object wrapper – C++11 – Part I

In this excellent presentation on C++ concurrency, Herb Sutter shows the importance of non-blocking application sofware, and goes on to develop a very useful “concurrent wrapper”. We present a working version of it, implemented using the concurrent queue from an earlier post, and tweaked to compile and run with GCC 4.7.2.


Concurrent queue – C++11

This is an implementation of the classic multiple producer, multiple consumer thread-safe queue concept. Much has been said about this before, but I need a simple, pure C++ version of this for future posts, so I thought I might as well say a few words about it. I had set a variant on this theme as an exercise in a C++11 workshop, and I also encountered a simplified variant of it in a job interview assessment question. It asked to implement a thread safe queue a single producer and a single consumer thread. The interface was minimal and clean:

template <typename T>
struct Queue
  // pop an element and return a copy. Block if queue empty.
  T pop();
  //  push an element to the back of the queue.
  void push(const T& item);