Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: crashing problem due to buckyball timer exception inNSAppleScript class



Chris Hanson wrote:
| NSAppleScript is not listed among the thread-safe Cocoa facilities at  
| <http://developer.apple.com/documentation/Cocoa/Conceptual/ 
| Multithreading/Concepts/safety.html>.  This means (1) that not only can  
| you not use it from multiple threads at once, but also (2) that you  
| also can't use it from any thread other than the main thread.

"Not thread-safe" (1) and "must be used only on the event thread" (2) are completely separate limitations. Neither one implies the other; you can have non-thread-safe classes which may be used in any thread, and you can have classes which must be used in the event-dispatch thread which are thread-safe.

| This applies to every piece of functionality that isn't thread-safe  
| unless explicitly documented otherwise.

"Not thread-safe" means only that the thread-unsafe item (variable, function, whatever) can't be safely used in more than one thread at the same time. However, it *can* be used from more than one thread as long as the uses *do not overlap*, as long as one thread is completely done with the item before another thread starts using it. (It's still generally best to limit *all* use of the item to a single thread, however, as it's very difficult to *guarantee* that the item won't be used from more than one thread at a time without taking the steps that would make the item thread-safe.)

In particular, a thing which is thread-unsafe is *not* restricted to use on the event-dispatch thread. It is merely restricted to *one* thread. whichever thread that happens to be. "Must be used on the event-dispatch thread" is a separate, additional requirement. It arises because the item is tied into the event-dispatching system in some fashion, either because it espects to get events sent to it, or because it uses data maintained by the event dispatcher, and the dispatcher isn't thread-safe. While it's usually true that items tied to the event-dispatch system (e.g., UI components) aren't thread-safe, that's so merely because it's usually not felt to be cost-effective to make them thread-safe, not because there's any inherent problem in doing so.

It's true that NSAppleScript must be assumed non-thread-safe (since it's not stated to be thread-safe), but that's not why it must be used only from the event-dispatch thread. *That* restriction stems from the fact that AppleScripts use events to send commands and data back and forth; the AppleScript must be run on the main event loop or the events it depends on won't get sent to it.


Glen Fisher


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >crashing problem due to buckyball timer exception in NSAppleScript class (From: IMD <email@hidden>)
 >Re: crashing problem due to buckyball timer exception in NSAppleScript class (From: Chris Hanson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.