Books on Grand Central Dispatch

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

  1. macrumors 6502

    Joined:
    Sep 8, 2006
    #1
    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 cimgf.com, but I still feel a little lost and could use the step-by-step explanations found in a book dedicated to the topic.
     
  2. macrumors regular

    Joined:
    Aug 21, 2011
    Location:
    Stockholm Sweden
    #2
    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.
    http://www.cs.rice.edu/~cork/book/node96.html

    // gunnar
     
  3. macrumors 6502a

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #3
    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. thread starter macrumors 6502

    Joined:
    Sep 8, 2006
    #4
    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. macrumors 603

    Joined:
    Aug 9, 2009
    #5
    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:
    http://developer.apple.com/library/...Multithreading/Introduction/Introduction.html
    http://developer.apple.com/library/...roduction.html#//apple_ref/doc/uid/TP40008091
    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