title: UIKit drawing is thread safe: how do you get a graphics context?
body: <p>So, as mentioned in <a href="https://stackoverflow.com/a/4557587/244340">this answer</a> and in <a href="https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS4.html#//apple_ref/doc/uid/TP40009559-SW29" rel="nofollow noreferrer">the iOS 4.0 release notes</a>, UIKit now has some thread-safe drawing facilities:</p>
  
  <blockquote>
    <p>Drawing to a graphics context in UIKit is now thread-safe. Specifically:</p>
    
    <ul>
    <li>The routines used to access and manipulate the graphics context can now correctly handle contexts residing on different threads.</li>
    <li>String and image drawing is now thread-safe. </li>
    <li>Using color and font objects in multiple threads is now safe to do.</li>
    </ul>
  </blockquote>
  
  <p>That's great, but how do you use it?</p>
  
  <p>As far as I'm aware, any time you're not inside <code>-drawRect:</code> you can only draw using the UIKit/UIGraphics stuff if you've created your own context through <code>UIGraphicsBeginImageContext()</code> or <code>UIGraphicsPushContext()</code>, but those functions are not thread safe according to the docs, and <code>-drawRect()</code> is always called on the main thread.</p>
  
  <p>I assume that creating an image context on the main thread and then starting the background method would be a really bad idea, due to race conditions aplenty.</p>
  
  <p>So, how do I use this multithreaded UIKit-based drawing stuff that was introduced in iOS 4? What other ways of getting an active UIKit graphics context have I missed?</p>
  
  <p>P.S. I know that I could just draw using Core Graphics and be done with it. For various reasons (legacy code) I'd like to continue using the UIKit based drawing methods.</p>