• 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: Threadsafe function help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threadsafe function help


  • Subject: Re: Threadsafe function help
  • From: Ken Tozier <email@hidden>
  • Date: Fri, 1 May 2009 01:21:32 -0400


On May 1, 2009, at 12:59 AM, Michael Ash wrote:

"It locks up" is not a very useful description. Use the debugger and
find out *where* it locks up.

I bracket calls to my KCLog function like so NSLog(@"about to call KCLog"); KCLog(@"testing 1, 2, 3"); NSLog(@"KCLog exe OK");

And what I see in the Xcode console is:
about to call KCLog

and that's it. It never make it to "KCLog exe OK"


I'll wager it's due to your manipulation of GUI objects in that last method you posted, though. GUI objects can *only* be manipulated from the main thread. You apparently know about this, because you dump your append calls onto the main thread using performSelectorOnMainThread:, but you fail to do this for a bunch of other calls, like length and scrollRangeToVisible:.

I could see where scrollRangeToVisible might cause a problem, but wouldn't "length" be OK since it is just reading a value, not changing it?



That entire method should really be on the main thread.

How do you do that? The console view is a singleton and is initialized in the AppController awake from nib method before anything else executes. Is that enough to insure it is running on the main thread? May seem like a silly question but I'm far from comfortable working with threads. I haven't used them enough to know where the pitfalls and gotchas lie.


Don't bother
trying to bump individual calls to the GUI objects onto the main
thread. At best you'll end up with tremendously confusing and somewhat
inefficient code. At worst you'll end up with weird race conditions
resulting from interleaving calls on different threads. Write a nice
easy method that does the update on the main thread, and then invoke
that whole method using performSelectorOnMainThread:.

Mike
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Threadsafe function help
      • From: "Stephen J. Butler" <email@hidden>
References: 
 >Threadsafe function help (From: Ken Tozier <email@hidden>)
 >Re: Threadsafe function help (From: Michael Ash <email@hidden>)

  • Prev by Date: Re: Threadsafe function help
  • Next by Date: Re: Threadsafe function help
  • Previous by thread: Re: Threadsafe function help
  • Next by thread: Re: Threadsafe function help
  • Index(es):
    • Date
    • Thread