Futures: asynchronous invocation
Posted on: 31/05/2010
In the concurrent world, a Future object refers to an object whose actual value is to be computed in the future. You can think of it as a handle to an asynchronous invocation of a computation that yields a value.
Many so called concurrent programming languages support this idea as a native construct offered by the core language itself. Unfortunately, C++ does not. Well, at least not in the current standard; C++0x (or shall I say C++1x ?) is going to support std::future as part of the massive new C++0x thread library, which is based on boost::thread. In this post we will implement a simple, yet very powerful, such future object.
Odd man out
Posted on: 24/04/2010
- In: puzzles
- 49 Comments
There’s nothing like the “Eureka” moment when you eventually manage to solve a challenging puzzle. I’m a man of puzzles myself, and the ones I like the most are computer science, or programming related, puzzles.
I’ve recently heard a pretty intriguing puzzle I would like to share with you.
Quines
Posted on: 16/04/2010
- In: tricks
- 5 Comments
A Quine is a computer program which prints a copy of its own source code as its only output.
Thus it is theoretically possible to compile such a program, run it, and then have its output compiled again to produce the initial program – in an infinite loop, forever.
- In: mechanisms
- 2 Comments
The handler std::terminate() is called whenever the exception handling mechanism cannot find a suitable catch clause for a thrown exception (and in some other cases. For example, when an exception is thrown during the handling of another exception – see this GotW post about std::uncaught_exception). It is possible to define a custom handler by using std::set_terminate.
In this post we would like to create a terminate handler which will be able to catch the exception that led to its invocation, when there is one.
Escaping overloaded operators
Posted on: 19/02/2010
- In: tricks
- 6 Comments
The possibility of overloading just about any C++ operator and having it do something entirely different from what it was designed for, can sometimes make life pretty hard.
Here are a couple of examples: What if you wanted to take the address of an object, which had implemented an entirely different semantic for the ampersand (&) operator? Or what if somebody decided to overload the comma operator in some strange manner?
As you could have guessed, there are solutions for such scenarios.
Recent comments