Archive for April, 2008

Thread Affinity on OS X

Tuesday, April 29th, 2008

My first experience in developing software to run on OS X has been a disappointing one. Previously, I have written software to run on Windows and Linux and in general I have found library or system API calls that provide me with the ability to access the services that I expect to be provided by the operating system. One such service is thread affinity – i.e. the ability to tie a particular thread to a given core. This is achieved using SetThreadAffinityMask() on Windows and sched_setaffinity() on Linux.

However, I was very surprised to find that it does not appear to be possible to do this on OS X! 

OS X Leopard introduced a thread affinity API which provides the ability to provide affinity hints to the scheduler to improve data locality in caches. Unfortunately this API does not provide the ability to tie a thread to a core. This is a major gap, especially now that all new PCs and laptops are multi-core.

So why do I want to be able to tie a thread to a core? I want to benchmark a piece of code and one of the data points of interest is to benchmark this code on a single core. With the current Mac OS X thread affinity API, this is not possible!

I’m finding it hard to believe that this service does not exist on OS X – I mean surely somebody must have wanted to run a single core benchmark on OS X running on a multi-core system. But after a couple of hours of googling and reading through the OS X APIs I have been unable to find out how to do this.

Coding The Architecture

Tuesday, April 22nd, 2008

I stumbled upon Coding the Architecture and found it to be a very refreshing and pragmatic view to software architecture and to the role of a software architect. I generally find that sites, blogs and articles on software architecture tend to focus on presenting a specific architectural process, modeling tool or on the latest trend in software architecture. Trying to find down to earth, practical advice on how to set oneself up for success as a software architect has proven difficult – until now. 

After browsing through some of the blog entries on the site and from one of its user groups, I am reminded of the resonant style of the Pragmatic Programmer book. It has the same practical and pragmatic feel. 

Some entries / articles that I found interesting:

ToDo Lists

Saturday, April 19th, 2008

Where would we be without ToDo lists? They have found their use in everything from keeping track of simple errands to keeping track of outstanding tasks in large scale projects. I find them an integral part of my day to day work and so over the years, I’ve tried out various ToDo list applications to try and find the one that the right fit for me.

I am constantly amazed by the vast number of different applications for managing ToDo lists that have emerged. They range from very simple single list tools, to complex tools that are more suited towards project management than they are for keeping track of what to get during the next visit to the shops.

ToDo list applications need to feel right when you are using them. I have all too often had the experience of trying out a particular ToDo list application only to find that it constrains my usage model in some way. I then spend a couple of days/weeks trying to adapt my usage model to the constraints and model offered by the application. I eventually get too frustrated and give up. I am convinced at this stage that different people are tuned to different ToDo list application features and that there is no one “ToDo list model” that fits all. In spite of this, I believe that I have found the magic ToDo list application that seems to fit most usage models – or at least it doesn’t provide any constraints about how to manage your ToDo lists so you have the freedom to manage them whatever way you like.

After trying 20+ different applications over the past 10 or so years, I constantly return to Abstract Spoon’s ToDoList application. This is without doubt one of the most flexible ToDo list managers out there and it acquires new features at a fast pace. This application really defines the meaning of feature rich. I have used it successfully for managing simple lists, project scheduling, time tracking, and SCRUM backlogs, burndown charts and even for online SCRUM boards. It is difficult to describe its feature list in a simple blog post so I encourage you to download it and give it a twirl.

The only downside that I have encountered with this particular application is that it is Windows specific. I’m sure that ports of this application to different OSes will occur with time but for the moment the cost of its excellent flexibility is only being able to use it on your Windows box(es).

Visual C++ 2008 Feature Pack Released

Wednesday, April 9th, 2008

Previous posts have mentioned the Visual C++ 2008 feature pack which was available as a beta release. The full version has been released and is available for download

The previously reported bug with array::max_size() has now been fixed.

Some TR1 related resources from Microsoft:

C++ Lambda Functions

Sunday, April 6th, 2008

A previous post showed a code snippet for dumping the contents of an STL container using an ostream_iterator. Things have now gotten a little bit easier with the introduction of lambda functions into the upcoming C++0x standard. Lambda functions allow pieces of code to be passed around as if they were ordinary objects. Applying lambda functions for dumping the contents of an STL container gives:

vector v(10);
generate(v.begin(), v.end(), rand);
for_each(v.begin(), v.end(),
    [](int& x){ cout << x << " "; }) [/sourcecode] OK, so the syntax looks a bit strange at first, but it does add a powerful construct to the language. Lambdas have only just been added to the C++0x standard and support for lambdas are not included in the beta version of the Visual Studio 2008 TR1 feature pack.

For more details and examples of lambda functions, check out Herb Sutter’s recent trip report from the February/March ISO C++ standards meeting.