• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Threads and UI
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threads and UI


  • Subject: Re: Threads and UI
  • From: Chris Hanson <email@hidden>
  • Date: Thu, 11 Dec 2003 11:02:42 -0600

On Dec 11, 2003, at 2:37 AM, Daniel Todd Currie wrote:
Otherwise I could set up an NSTimer and call some sort of messenger method (since I can't call drawRect: with a timer directly), which seems like a bit of a kludge.

You should set up a timer, and in that timer send a -setNeedsDisplayInRect: or -setNeedsDisplay: to the view you want to animate.

You shouldn't send a view -drawRect: directly to make it draw; Cocoa does double-buffering and manages the drawing state to minimize the actual amount copied to the screen. Among other things, this means your window's contents will only actually be copied to the display during the vertical blanking interval to eliminate tearing.

In your view's -drawRect: method, you should check the current time and determine what to draw based on that, rather than draw "the next increment." Timers aren't guaranteed to be hard-real-time, and you'll get smoother animation if you draw the right thing for a given time rather than just the next thing in a sequence.

Aside from this specific question, can someone perhaps describe what is meant by "thread safety" and the potential risks of UI updates outside of the main thread?

"Thread safety" means synchronizing access to shared data structures in order to guarantee that they're always in a consistent state.

That's the one-sentence summary; there's more detailed information in pretty much any documentation on multithreading you can find, whether it's the POSIX threads documentation, the NSThread documentation (be sure to read the conceptual stuff, not just the API reference), etc.

-- Chris

--
Chris Hanson <email@hidden>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Threads and UI (From: Daniel Todd Currie <email@hidden>)

  • Prev by Date: cocoapad
  • Next by Date: NSBorderlessWindowMask window with NSTextView
  • Previous by thread: Re: Threads and UI
  • Next by thread: NSConnection on same machine between different users (via 10.3 fast switching)
  • Index(es):
    • Date
    • Thread