Books on Grand Central Dispatch

Discussion in 'Mac Programming' started by klaxamazoo, Feb 1, 2013.

  1. klaxamazoo macrumors 6502

    Sep 8, 2006
    Are there any good books on using Grand Central Dispatch? I've found:
    Concurrent Programming in Mac OS X and iOS

    but I wanted to know what books people recommend. I'm not a programming expert and I'm looking to learn how to properly implement concurrency. For example, I want to do any importing or parsing on a separate thread, but be able to stop the parsing process if the user selects a different file. That way there isn't a big lag between selections.

    I've gone through the Concurrency Programming Guide and read some posts on, but I still feel a little lost and could use the step-by-step explanations found in a book dedicated to the topic.
  2. ghellquist macrumors regular

    Aug 21, 2011
    Stockholm Sweden
    Hmm. Looks like a quite convoluted way of doing things. Might be good in very special circumstances.

    Look at "normal" concurrent programming instead, here is one example.

    // gunnar
  3. mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    GCD is a tool to help with multi-threading. It can be a useful way to break a problem down into steps. But it isn't the only way to handling threading. When you have several tools (like GCD) available, it's a good idea to use tools that make sense. Having written some code that uses GCD, I would say that file processing is probably not something GCD is best used for. Instead, I would create a separate thread and just let that separate thread read the file. No GCD stuff is needed.

    If you're making a GUI app, then the main thread would be handling the UI. If the user presses the "stop" button, then the main thread can set a "stop now" flag. The file processing thread should check that flag (for example, every time it reads a line in the file) and stop reading if the flag is set.

    You will need to perform synchronization of data between the file-reading thread and whatever logic is consuming the data being read in the file.
  4. klaxamazoo thread starter macrumors 6502

    Sep 8, 2006
    Thanks for the recommendations. I guess that is why I'm looking for a book that details how to properly implement multithreading/GCD so that I don't tie up the main thread anymore. I would like to know when to use it, how to use it properly, what are the best practices, how to deal Core Data and Views, etc.

    I'm looking for a book because they usually have examples that start with something simple and slowly build upon it while discussing why things are done this way. Once I have a basic understanding behind the concepts and how to implement them, it is much easier to go through Apples documentation or example code.
  5. chown33 macrumors 604

    Aug 9, 2009
    It's difficult to suggest a book without knowing where you are in your understanding of threading, and what experience you have working with it, if any.

    It would help if you listed what references, tutorials, examples, etc. you've already gone through. Also, if you've had difficulties with some reference or tutorial, exactly where was the difficulty.

    Examples of relevant Apple docs:
    Cocoa Core Competencies

    You seem to be using the terms threading and GCD almost interchangeably, when they are anything but. Because parsing deals with streams of data, and you want its action to be interruptible, it makes more sense to use a thread, in the way mfram pointed out (a "stop now" flag). GCD blocks are more oriented towards performing a single well-encapsulated action to completion. A typical parser would have to be "turned inside-out" in order become a set of dispatchable yet sequence-interruptible blocks (effectively a finite-state machine)

Share This Page