Showing posts with label Multithreading. Show all posts
Showing posts with label Multithreading. Show all posts

Tuesday, April 29, 2008

Thread Affinity on OS X

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.

Friday, February 22, 2008

Effective Concurrency ... so far

Following on from a previous post about The Pillars of Concurrency, here are links to the full set of Herb Sutters "Effective Concurrency" column topics (as of Feb 2008) ...

The Pillars of Concurrency
How Much Scalability Do You Have or Need?
Use Critical Sections (Preferably Locks) to Eliminate Races
Apply Critical Sections Consistently Avoid Calling Unknown Code While Inside a Critical Section
Use Lock Hierarchies to Avoid Deadlock
Break Amdahl's Law!
Going Superlinear

These are an excellent set of articles on the subject of concurrency and programming for multi-core that analyzes the many facets of the subject - from background theory, to locking and on to achieving scalability and performance.

Friday, July 6, 2007

Pillars of Concurrency

Excellent article on decomposing and categorizing concurrency traits by Herb Sutter ... http://www.ddj.com/dept/cpp/200001985

The three "pillars" identified in the article:
  1. Responsiveness and Isolation Via Asynchronous Agents
  2. Throughput and Scalability Via Concurrent Collections
  3. Consistency Via Safely Shared Resources

An interesting reference from this article is to an earlier article from Herb illustrating why lock based programming is hard and insufficient: http://www.ddj.com/dept/cpp/184401930