February 13, 2017

I made a topical cartoon. #inadvertently

Against the Bubble

January 12, 2017


Remembering 9/11

September 11, 2016

World Trade Center Twin Towers

Credit: Jeffmock CC-BY-SA-3.0

On this 15th anniversary of 9/11, I recall my most vivid memory of the events. I drove in to work at Honeywell Aerospace in Kansas City after watching the second aircraft crash into the Twin Towers on live TV. Partway through my drive, I saw something I’d never seen before or since: arcing contrails, all over the clear blue Kansas sky. It wasn’t after I got in to work that I found out that the FAA had grounded all aircraft in flight. Those contrails showed where aircraft turned around and landed where they came from.

We didn’t get much work done that day. Someone hooked up large screen TVs and we watched as the towers fell.

Keeping Things Straight with GCD

June 14, 2016

GCD Logo

This is the sixth and final post in a series about Grand Central Dispatch.

Long time users of GCD will tell you: it’s easy to forget where you are. Which queue am I on? Should I dispatch_sync to a queue that protects my variables, or has my caller taken care of that?

In this post I will describe a simple naming convention that has kept me sane over the years. Follow it, and you shouldn’t ever deadlock or forget to synchronize access to your member variables again.

Designing thread-safe libraries

When designing thread-safe code, it helps to have a library mindset. You should distinguish between the external or public interface (API), and the internal or private interface. The public API is presented in public headers, and the private interface is presented in private headers, used only by the library’s developers.

The ideal thread-safe public API does not expose threading or queueing at all (unless, of course, thread or queue management is the point of your library’s utility). It should simply not be possible to induce a race condition or deadlock when using your library. Let’s take a look at this classic example:

// Public header

#import <Foundation/Foundation.h>
// Thread-safe

@interface Account: NSObject
@property (nonatomic, readonly, getter=isClosed) BOOL closed;
@property (nonatomic, readonly) double balance;
- (void)addMoney:(double)amount;
- (void)subtractMoney:(double)amount;
- (double)closeAccount; // Returns balance

@interface Bank: NSObject
@property (nonatomic, copy) NSArray<Account *> *accounts;
@property (nonatomic, readonly) double totalBalanceInAllAccounts;
- (void)transferMoneyAmount:(double)amount
                fromAccount:(Account *)fromAccount
                  toAccount:(Account *)toAccount;

If it weren’t for the helpful comment, you wouldn’t be able to tell from this header that the library is thread-safe. In other words, you’ve defined thread-safety as an implementation detail.

Read more…

Seven Seas Park at Night

February 24, 2016

Seven Seas Park at night

See this photo in my flickr album

The lights went out at Seven Seas Park (darn copper thieves!). This gave me an opportunity to capture the full moon over the townhomes lining the park’s perimeter. If you look closely you can see a full halo around the moon, courtesy of some light cirrus clouds.

📷 Nikon D800, Nikon 14-24mm f/28 at 14mm, 20 seconds at f/5.6.

< Newer Posts