How Threading Works

Preston Holmes explains how threading works in Frontier.

Question: What if you need a return value after processing? I'm thinking of CGI's, really. How does that work? I want to take advantage of threads, but wonder how you get a value back after you "let go"...

Answer: Each AppleEvent that triggers Frontier to 'do something' will spawn a new thread. In the case of CGIs each request to a webserver (assuming a threaded webserver) will create a thread in the server, the server will send an event to Frontier, which spawns a thread to run the CGI.

Now those two threads are 'on the phone together'. The webserver thread will wait for a response from Frontier - in this case nothing is let go. While the 'conversation' between these two threads goes on, the server (being threaded) can receive more requests, and Frontier (being threaded) can run additional CGIs (and the same CGI script can run in more than one thread).
Threads are handled in the correct order (unlike AS) with the first request being received being the first evaluated and returned. Frontier not only provides a threaded environment for CGIs but an entire CGI framework that takes care of all the busy work out of CGIs. The CGI request is fully parsed into a set of ready to use variables, and all errors are handled in the framework (you could also handle them yourself if you want to return a custom error page).

Filemaker sends a 'dosc' (do script) event to Frontier. Frontier spawns a new thread. Now Filemaker and Frontier are 'on the phone together', which means that if Frontier (or Applescript) tries to get infromation from Filemaker (which is NOT threaded), its gonna get a 'busy' signal (it does work but is very very slow).

If instead the Frontier script took the script to run from FM and used the evaluateThread () verb to start the script in a 3rd thread (1 is the main thread, 2 is the thread started by FM's initial request) than FM would receive 'true' and free itself up to other events. In this case returning a value was not considered important, since Frontier can set FM data directly.