I haven't tried to do anything like this myself, and I doubt that anyone else has: you're pioneering, and I can't really give you much advice. I'm happy to answer technical questions about the interfaces available, but I can't offer to help with the design of a solution to your problem.
 
It's far from clear from your description how you would like this all to work. One piece of advice I would give (which I learnt the hard way from the design of the SQL extension many years ago) is that it's best not to have any hidden run-time state or context. If calling one function depends on the result of a previous function, then it's best to make the dependency explicit by having the first function return some kind of object which is then passed as an argument to the second function.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Full Midnight [mailto:full.midnight@gmail.com]
Sent: 13 May 2010 11:01
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Saxon 9.2 / Java: XSLT & Integrated extension functionsscope in a multi-threaded context

Hi all,

The following requirement is currently encountered in my application: an integrated extension function (implemented in Java using Saxon 9.2) that sometimes needs to be executed as a separate thread, depending on how the user calls this extension function. The result of this extension function will be a NodeInfo. This result should be returned back to the transformation (no matter if it was called in a single or multi-threaded manner).

Basically what is expected (not sure however if also possible) is that at some point during the transformation, I will have our extension function (noted with f below) which needs to be properly handled:
<f name="f1" threaded="no"> f1 will wait for f2 to complete and only then will return
    <f name="f2" threaded="yes">
        <f name="f3" threaded="no"/>   --> f2 waits until f3 completes execution and only then continue with f4
        <f name="f4" threaded="yes"/> --> f4 is executed as a separate thread. f2 will continue execution with <otherstuff/> and will wait for f4 to complete (only then f2 will return)
        <otherstuff/>
    </f>
</f>

Because I am lacking the details of how Saxon deals with such a scenario, I would like to ask how this works in the Saxon XSLT processor and, eventually, how to handle this situation accordingly / better / more wisely. Any available hints / posts / articles / code in which such a scenario is presented is highly welcomed.

Thank you in advance!