Re: AppleScript's Threadedness…
Re: AppleScript's Threadedness…
- Subject: Re: AppleScript's Threadedness…
- From: Chris Page <email@hidden>
- Date: Wed, 10 Dec 2008 22:35:11 -0800
On Nov 19, 2008, at 3:01 PM, has wrote:
Idle curiousity, but I've occasionally wondered if it'd be possible
to use AS on a single background thread if you install your own send
proc (to receive Apple events via a dedicated mach port). Or does
the interpreter have other dependencies on the main thread as well?
Just to satisfy your curiosity: If you're very, very careful, you may
be able to get away with it for a while. But don't do it, because it's
not guaranteed to work and may break in the future.
There are a number of issues you'd have to carefully control to avoid
bugs or crashes. For example, you need to supply a send proc to
arrange to execute events addressed to the current process on the main
thread, since Apple Event handlers are not guaranteed to be thread-
safe. Also, you can't control this for coercion handlers, since they
don't go through events. If you do this, don't assume events for the
current process are always addressed to kCurrentProcess -- they could
be addressed to the current process's process serial number or pid (or
bundle ID, etc.). Also, don't assume your send proc will always be
called on a particular thread. Always check which thread it's being
run on.
One serious problem that's out of your direct control is that OSA and
AppleScript frequently open and access resource files, but the
Resource Manager is not thread-safe.
--
Chris Page
The other, other AppleScript Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden