• 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 & NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threads & NSTextView


  • Subject: Re: Threads & NSTextView
  • From: Chris Hanson <email@hidden>
  • Date: Sat, 23 Jul 2005 09:50:12 -0700


On Jul 23, 2005, at 8:16 AM, Laurent Michel wrote:

Since I did not see NSTextView listed in the thread-safe cocoa objects, I made sure to call

BOOL isLocked = [console lockFocusIfCanDraw];
...
if (isLocked) [console unlockFocus];

around the code that appends the text at the end of the TextStorage object.

Appending text to an NSTextStorage is not a drawing operation.

How does one /properly/ locks an NSTextView to update its content from a separate thread ? Should I lock the parent view ? How should I lock ? which API ?

There is no way to properly lock it, because there's no way to force Cocoa to use your lock when interacting with it.


This is true pretty much any time you're talking about using non- thread-safe classes. If your code was the only thing interacting with their instances, you might be able to lock around all uses. However, since you're using a framework, your code isn't the only code interacting with them, and you can't force code that isn't yours to respect your locks.

You'll need to instead make sure that updating the text storage happens on the main thread. This is just the kind of situation - [NSObject performSelectorOnMainThread:withObject:waitUntilDone:] is for.

  -- Chris

_______________________________________________
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: Threads & NSTextView
      • From: Laurent Michel <email@hidden>
References: 
 >Threads & NSTextView (From: Laurent Michel <email@hidden>)

  • Prev by Date: Re: getting bytes out of NSData
  • Next by Date: Re: Copying ABPerson (problem with MultiValue fields)
  • Previous by thread: Re: Threads & NSTextView
  • Next by thread: Re: Threads & NSTextView
  • Index(es):
    • Date
    • Thread