• 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: Threading and NSViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threading and NSViews


  • Subject: Re: Threading and NSViews
  • From: Karim Morsy <email@hidden>
  • Date: Tue, 21 Mar 2006 01:41:17 +0100

All the same, what makes you think that a timer would be inefficient?

in one of my previous posts I've been told that I could get into trouble if I was using to many timers too often per second. I have 2 timers for drawing an olpenglview (every 0.05 seconds), one timer that draws 4 views (every 0.02 seconds), and probably one or two more that update information to the user and that are not as performance consuming as the other timers ... do you see a problem here and if so, would you know a solution to it?


thanks,
Karim




On Mar 20, 2006, at 10:46 PM, John Stiles wrote:

performSelectorOnMainThread would be the safest way to go.
All the same, what makes you think that a timer would be inefficient? I think a timer would be more efficient than calling performSelectorOnMainThread 50 times a second.



On Mar 20, 2006, at 1:28 PM, Karim Morsy wrote:

thanks for the hint, kaelin!

as far as threading is concerned, I have one more question about views.
so far I've been drawing a view on the main thread and redrawn it with a timer every 0.02 seconds. to save performance, instead of firing the timer on the main thread I would like to perform the drawing on a secondary thread that runs in a while(true) loop, sleeps for 0.02 seconds and repeatedly redraws the view.


so far I've been doing this (to periodically draw 4 views):
- I detach the drawing thread
- within that thread I do:
BOOL canDraw = [mView[i] lockFocusIfCanDraw];
if(canDraw) {
[mView[i] updateView: &values]; // in updateview: I do some calculations and then call setneedsdisplay on self
[mView[i] unlockFocus];
}
- sleep for 0.02 seconds
-repeat


so far, most of the time this has been working fine, except for some tiny mis-drawings that sometimes occur (from which I assume that I'm missing something here).
I've read several articles and docs about multithreading in cocoa and it's said one has to be really cautious when drawing on seperate threads.
so I'm wondering wether the approach above is a good and most importantly correct one + is there a better / more efficient alternative ?


thanks again,
Karim





On Mar 20, 2006, at 8:56 PM, Kaelin Colclasure wrote:


On Mar 20, 2006, at 11:52 AM, Kaelin Colclasure wrote:

On Tiger and later systems, you can use Darwin notifications. Any thread can register for them, and they are trivial to post:

    notify_post("self.fileInitCompletedNotification");

If you elide the "self." prefix, they can even cross process boundaries.

I should rather say, "If you replace the "self." prefix with a reverse domain name prefix (e.g. "com.example.")..." (This mitigates the problem of name collisions.)


-- Kaelin


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Threading and NSViews
      • From: John Stiles <email@hidden>
References: 
 >Question on thread communication (From: Karim Morsy <email@hidden>)
 >Re: Question on thread communication (From: Kaelin Colclasure <email@hidden>)
 >Re: Question on thread communication (From: Kaelin Colclasure <email@hidden>)
 >Threading and NSViews (From: Karim Morsy <email@hidden>)
 >Re: Threading and NSViews (From: John Stiles <email@hidden>)

  • Prev by Date: Re: Tables created in code have different row height from those created in IB
  • Next by Date: Re: CGBitmapContextCreate hates me
  • Previous by thread: Re: Threading and NSViews
  • Next by thread: Re: Threading and NSViews
  • Index(es):
    • Date
    • Thread