On 18, Jul, 2012, at 04:17 AM, Martin Wierschin <[email protected]> wrote:
>> So my potential solution for this is:
>>
>> NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
>> __block NSRange range = NSMakeRange(0, 0);
>> while (range.location < [aString length]) {
>>
>> dispatch_sync(dispatch_get_main_queue(), ^{
>> range = [checker checkSpellingOfString:aString
>> startingAt:range.location];
>> });
>>
>> // update range
>> }
>>
>> Where this piece of code will run on multiple threads.
>>
>> Does this look like a reasonable approach to ensuring thread safety?
>
> In addition to the potential for deadlocking that Mike warned about, it's
> probably best to be paranoid about +sharedSpellChecker. Hopefully that method
> uses a thread-safe singleton allocation (eg: via dispatch_once), but you
> never know. I'd move that method call to the main thread too.
>
> However, by using this approach you're not really doing the spell checking
> work on a background thread. The work is going to be done synchronously on
> the main thread, blocking your GUI (and whatever else). Maybe you should
> investigate using -requestCheckingOfString:etc: instead.
Oh, this looks perfect. Don't know how I missed that API!
Thanks,
Martin
>
> ~Martin
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: [email protected]
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]