Concurrency : Concurrent (wrapper)

Herb Sutter presented in C++ and Beyond 2012 a very useful concurrency pattern that is an improvement from the “active object“.

concurrent wrap any object and all calls to the object will be executed asynchronously and in FIFO order.

Basically it is an improved active object that can wrap any object. The improvement from the active object pattern is that the boiler plate code to get an object asynchronous is completely removed!  The asynchronous function call on the object will be forwarded from a wrapper object to the actual object through a message queue.

// "hello" will be copied into a temporary std::string
// that will the input to the concurrent
// wrapper
concurrent<std::string> async_string{"hello"};

// Calling it is done through a lambda. The call
// is asynchronous. The job is executed in a background thread
async_string( [](std::string& s) { s.append(" world"); } );

The API call is always through a lambda or a std::function.   Continue reading

Video | Posted on by | 1 Comment

2013 in review

The stats helper monkeys prepared a 2013 annual report for this blog. It was a crazy year with relocating the whole family to the USA and trying to find a the  best location and company to work for.  The blog was not that active during 2013 but will be more active in 2014.

Coming up is the pending, official, release for G3log with some C++11 concurrency tech that might interest some coders.

A whole other story that is in the queue of tales to write is the whole moving process and what we learned from it.  There should be some goodies there for other people who is in the process of moving across the pond.

Below is an excerpt of the blog report.

Happy New Years!


The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 28,000 times in 2013. If it were a concert at Sydney Opera House, it would take about 10 sold-out performances for that many people to see it.

Click here to see the complete report.

Posted in Uncategorized | Leave a comment

G2log with Clang., Now with all the bells and whistles

At reddit I found that it was possible to get futures and std::thread to play nice on Linux/Clang.

I have updated my previous post “g2log with Clang++” with the details so that you can get Linux/Clang (and g2log) with all the bells and whistles of C++11.

All the clang limitations on G2log is therefore removed and Clang users can now enjoy the fully featured G2log.

I am currently working with G3log and Clang. So far G3log supports Windows (VS2013, mingw) and Linux (g++) and I hope to get Clang up and running.

Posted in C++, G2log | 4 Comments

Experimental : g2log with Clang++

After several requests to release g2log with Clang support I finally yielded. From today g2log will have experimental support for Clang. Why the Clang support is experimental is just because I have no OSX machine to test it on. So all Clang testing was done on Linux.

Clang users on Linux and OSX are welcome to try it out:

Continue reading

Posted in Uncategorized | Tagged , , , | 1 Comment

Rethinking the coding IDE : SourceKit App on Google Chrome

For the last couple of months I have tried to study up for coming job interviews. This typically means finding an area where I am rusty and make it shine. As I do this I find myself going through my old favorite IDEs and discarding them.

Instead I find myself using IDE combos that I never would have considered before and as a result I am starting to visualize the way I would like to work with my IDE.

Continue reading

Posted in C++, coding, Software Engineering | Tagged , | 5 Comments

Exploring C++11, part 2 (localtime and time again)

C++11 time, part II. Part I you can read here:
Several of the time functions in C++ are not thread-safe and using for example std::localtime or std::asctime can have unwanted side-effects. Other thread unsafe c-library functions that come to mind are std::ctime and std::gmtime. The compiler will likely point out any use of these unsafe functions by generating warnings.

It is nice to know that there is an easy way to make your time code thread-safe and as a bonus getting rid of the compiler warnings.

Depending on your platform the std::localtime can be replaced for platform dependent localtime_r or localtime_s.

std::asctime and std::ctime have _r and _s equivalents but a much better option is to use the std library functions std::strftime and std::put_time.

That is really all you need to avoid problems. Do you want to know details? If so, read on …
Continue reading

Posted in C++ | Leave a comment

C++ Debt Paid in Full? Wait-Free, Lock-Free Queue

In 2009 I wrote about a horrid lock-free Single Producer, Single Consumer Circular Fifo that I had seen in use in the industry. I tried to pick it apart and see what made it tick. Was it broken beyond reason or could it actually work? It was an attempt to understand without recommending the sketchy platform hack.

Of the C++ topics I have written that first article seemed to attract the biggest crowd at CodeProject.  A double-edged sword to say the least since I liked the feedback but did not like the thought of happy coders using something that was not at all kosher. Something that could break their shiny code when they least expected it.

Now with C++11 <atomic> it is a snap to write the wait-free, lock-free simple Single Producer, Single Consumer CircularFifo. Of all the lock-free structures out there, this got to be the easiest to grasp.

I just finished overwriting my old article. The old article is still saved with a nice revision tag but you have to dig to get to it.

For early reviewers here is my own snapshot of the revitalized article.  Its’ not yet spell corrected mirror but with nicer formatting can be found here CodeProject: Lock-Free Single Producer [...]


Continue reading

Posted in C++ | 6 Comments