Under The Microscope

Archive for December, 2008

An RAOperationQueue fix

We’ve updated RAOperationQueue to fix a buffer overflow bug which could lead to a crash. Download the new version of RAOperationQueue here.

Thanks go to David Smith and the Adium project for reporting this bug.

The bug was due to improper use of the mach_msg call. The old version of RAOperationQueue didn’t allocate space for a message trailer, which is required. Although we informed mach_msg that our buffer was small, it ignored us and wrote right off the end. Hilarity once again ensued.

For more info on what RAOperationQueue is and why you might want to use it, see RAOperationQueue, an open-source replacement for NSOperationQueue.

python 3.0

James Bennett: Python 3.0 was designed to clear up a lot of now-inertial legacy issues with the Python language and figure out good ways to do things now instead of unquestioningly sticking with what seemed like good ways (or, more often, the least painful ways) to do things five or ten years ago. (via Michael Tsai)

Although I do not look forward to porting all the code we have from python 2.5 to python 3.0, I very much look forward to python 3.0 when we get there.

More Radioshift Improvements

Radioshift IconWe’ve got another minor update to Radioshift today, with several improvements to make it run even more smoothly. Back in November, we added a new MP3 playback engine to Radioshift to improve playback on thousands of streams. With version 1.1.2, we’ve worked to make this engine even more robust, handling malformed MP3 streams and more. As well, we’ve improved Radioshift’s search functionality to provide faster results.

This is a free update for all licensed owners of Radioshift, so all existing users should simply click to download. If you haven’t experienced the best way to listen to and record radio on your Mac, check out Radioshift now with a free trial.

Our Own Embarrassment Of Eddys!

Macworld Eddy 2008A group of witches is a coven. A group of crows is a murder. And according to Dave Nanian of Shirt Pocket Software, a group of three or more Eddy awards is known as an embarrassment.

With a 2008 Macworld Editors’ Choice Eddy Award for our own Airfoil, we’ve now got our own embarrassment! This trophy will stand proudly alongside Nicecast’s 2004 Eddy and Fission’s 2006 Eddy.

Airfoil IconCongratulations are due to all the winners this year. Among them are several of my favorite products, including VMWare’s Fusion, BusyMac’s BusySync and the joint NBC-Fox site hulu.com. Be sure to read the full list for all kinds of great products.

And of course, if you need to send any audio to an AirPort Express, to an AppleTV, and/or to any Mac, PC or Linux computer around your house, check out Airfoil. It’s got the Macworld stamp of approval and it’ll get your music from here to there, without the need to run miles of cables. So take a test drive of Airfoil for Mac (and Airfoil for Windows, sporting much of the same functionality) right now, then purchase in our online store!

RAOperationQueue, an open-source replacement for NSOperationQueue

When we started on our first Leopard-only software, we were excited to to use NSOperationQueue, as it promised to greatly ease the pain of multithreading. And it lived up to its promise well, right up to the point where we discovered that it was fatally broken.

(And I mean fatally broken. It spontaneously crashes. There’s no workaround and it’s unlikely that it will get fixed in 10.5.)

By that time we had already written a ton of code that revolved around NSOperationQueue. If it weren’t unusably broken, it would have been a great way to work. So we decided to simply write our own replacement instead. Since NSOperationQueue is a nice API, and since we all hate crashy Mac OS X software, we decided to release it to the world so that we can all benefit.

You can download RAOperationQueue here.

Note that this is not a 100% drop-in replacement for NSOperationQueue. Since it was written for our code, it only does what we needed it to do, so it has some limitations. Specifically, RAOperationQueue:

  • Only supports one running operation at a time in each queue. In other words, equivalent to setMaxConcurrentOperationCount:1 no matter what.
  • Only supports two priority levels.
  • Has no support for inter-operation dependencies.
  • Has no support for “concurrent” operations which don’t need to be run on a worker thread.
  • Spawns one worker thread per queue instead of sharing a pool of worker threads.
  • Perhaps some others.

However it also has some significant benefits:

  • 100% lockless and non-blocking in all circumstances, except that the worker thread will block when no operations are pending.
  • Full control over worker threads, can potentially set custom priorities or other thread properties.
  • Shouldn’t crash. If it does, you have the code and can fix the problem!

Whether you can live with the limitations is of course something only you can decide, but we’re making very good use of this code internally, and we hope that you can too.

Comments, questions, bug fixes, and other contributions are welcome by e-mail to mikeash at this domain.

RAOperationQueue is made available under a very liberal license which just requires a mention in your about box. We hope you’ll find it as useful as we have.

Update: As of Mac OS X 10.5.7, NSOperationQueue is fixed and safe to use again.