A pthreads Tutorial

I’m going to use a simple program to illustrate the basic use of pthreads, and highlight some of the issues that you may run into when you’re creating your own threaded programs (for C++11 threads, see this post).

I want my program to print a message from each thread I create, to the console, in a different colour.

I’m going to build the program up in three steps, and talk about the issues we encounter on the way. I’m not going to go deeply into the pthreads calls – if you want to read about them in detail, there is an excellent break down and set of tutorials here.

Threads program, version 1 – faulty

Right, so here’s my first version of the program: threads1.cpp. Build it with:

g++ threads1.cpp -lpthread

Take a look, and I’ll talk through what I’ve done below.

Read moreA pthreads Tutorial

Function Templates In C++

We looked at a very straightforward class template last time, which should have given you the confidence to get started in creating your own template classes.

Now, to round off this introduction to C++ templates, we’ll just have a quick look at function templates, and talk a little more about the workings behind template source code.

As usual, we’ll start with the code, and then dissect it below in order to understand what is going on.

Here’s an example program:

Read moreFunction Templates In C++

C++ Templates Made Easy

Templates.

Groan.

With their godawful syntax and impressive verbosity it’s no wonder we screw our faces up in distaste when we see them in code. ESPECIALLY when we’re debugging that code. Oh my. It’s enough to make you wish you were writing the software for musical birthday cards instead (does anyone actually do that?).

Anyway, I’ve wanted to talk about templates for a long time but the approach is a tricky one because even hearing the dreaded ‘T’ word is enough to make people run for the hills. I probably should have put that in angle brackets. The dreaded <T> word. Ha ha.

Anyway, here we go, let’s dive in together because there is safety in numbers.

Templates – made easy. I promise 🙂

Read moreC++ Templates Made Easy

make: Nothing to be done for ‘all’ – Eclipse Error Solved

I’ve seen this odd error several times over the years, almost always after first importing a new project into Eclipse-CDT.

After import, when you try to build your project, it just returns the message make: Nothing to be done for all in the console.

And then, once you’ve got the error, nothing you do will kick your build into action – changing files, changing project settings, even deleting and recreating build configurations.

If you try to run the executable, you just get Launch failed. Binary not found.

Because, of course, make hasn’t built anything.

Aargh!

Annoying, eh?

Read moremake: Nothing to be done for ‘all’ – Eclipse Error Solved