Edaqa Mortoray maintains a blog about programming at mortoray.com.

How does a mutex work? What does it cost?

16-Dec-2011
Programming

Concurrent programming requires synchronisation. We can't have more than one thread accessing data at the same time otherwise we end up with a data race. The most common solution is to wrap the critical data access in a mutex. Mutexes are, of course, not free.

Read Article...

How Polymorphism Works - Part 2 - Virtual Table

12-Aug-2011
Programming

In the article on "How Polymorphism Works: Part 1" we learned how to create virtual functions. The method which we chose has at one significant problem with it: it requires a lot of memory and repeated initialization.

Read Article...

How Polymorphism Works

09-Aug-2011
Programming

Polymorphism: the core of object oriented programming. Most modern languages have some concept of interfaces, virtual functions, and classes. Though each language differs in details, and may have specialized concepts, the core idea remains the same.

Read Article...

What is an atomic operation?

23-Mar-2011
Programming

We all know that operations in a computer happen one after the other. Having multiple CPUs and instruction reordering tends to obfuscate the issue. Technically things still proceed in an orderly fashion, but logically the interleaving of instructions and memory may seem perplexing.

Read Article...

CPU Memory - Why do I need a mutex?

18-Nov-2010
Programming

Multi-threaded programming calls for semaphores, synchronized blocks, mutexes, or whatever your language happens to call them. Most of us basically understand why we need them: to prevent multiple-threads from accessing the same memory.

Read Article...

CPU Reordering - What is actually being reordered?

18-Nov-2010
Programming

We've all heard that a CPU may reorder access to memory. Yet if you've looked further you'd also see that cache coherence ensures the memory is kept in sync at all times. Something doesn't quite add up.

Read Article...

The Cost - A Function Call

12-Oct-2010
Programming

In the grand scheme of execution costs function calls come very close to the bottom of the list. They don't cost very much at all -- at least not in most compiled languages. It is nonetheless interesting to examine the costs involved.

Read Article...

The Cost - Instantiation and the hidden enemy "new"

03-Oct-2010
Programming

Whether C++, Java or any other language, we are all familiar with instantiating an object. In those aforementioned languages the operator new happens to do just that. Obviously CPUs don't have any instruction nearly so high-level as to even approach the meaning of new.

Read Article...

The Cost - Programming Performance and Efficiency

03-Oct-2010
Programming

As high level languages become more abstract, and offer more convenience features, it is easy to lose track of what the computer is actually doing.

Read Article...

Curiously protective C++ code

14-Jun-2010
Programming

Working with a bit of code last week I stumbled into something unusual. I was working on something quite basic so kind of surprised when I came across a compilation error. GCC was telling me that I couldn't access a protected member.

Read Article...