Amro Mousa

iOS developer, BMW fan, and amateur photographer.

Page 2

GCD: Using Dispatch Groups for Fun and Profit

I’m republishing this article here so I can reference it later.

I recently needed a way to perform an unknown number of asynchronous http requests and wait until they were all done before proceeding. dispatch_groups are a neat feature of Grand Central Dispatch (GCD) that made this easy to do.

There are a couple of ways to use dispatch_groups but the basic idea is the same: create a dispatch_group, give it some tasks, and wait for it to finish those tasks.

First, let’s create a group:

dispatch_group_t group = dispatch_group_create();

There are two ways to add tasks to our dispatch_group. You can either call dispatch_group_async with the group, a dispatch_queue and block to run or manually call dispatch_group_enter.

Calling dispatch_group_async looks something like this:

dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // Do stuff on

Continue reading →

Jarek’s Anecdote

I’ve just started reading Ed Catmull’s book, Creativity, Inc. Early on Ed explains that he came up with both the z-buffer and texture mapping techniques that had a profound impact on my childhood (Threewave CTF in Quake 1, anybody?). This reminded me of an anecdote the instructor of my second graphics class once shared.

Jarek Rossignac told us about his giving a talk during his tenure as a researcher at IBM. Jarek’s talk was about his research of subdivision of curves. After the talk, a gentleman struck up a conversation with him. That gentleman ended up being Pierre Bézier, the man who popularized the Bézier Curve.

Continue reading →