[e-lang] E-on-Java: How to synchronously access a vat from an external thread?

Kevin Reid kpreid at attglobal.net
Sat Jun 25 18:50:47 EDT 2005


On Jun 25, 2005, at 15:02, Mark Miller wrote:

> Kevin Reid wrote:
>> Simple description:
>> I have a Java thread from which I want to invoke a function written 
>> in E. The Java thread did not start out as an E runner thread.
>> I see two methods:
>> 1.
>> Run the E code in its own default headless Vat/Runner and use some 
>> variety of inter-thread communication. The closest thing I've found 
>> is Vat#now/1, which does not provide for a return value.
>
> ...In any case, it's easy to work around this limitation by providing 
> a Runnable that stores the return value in an internal field whose 
> value you can then access.

Yes, but this would break the inter-vat reference constraints. (What's 
a better term for that?) The particular data I have in mind right now 
is all Strings, but if it wasn't, this would be unsuitable as a general 
solution.

I'll do this for now, anyway.

>> I assume I need to use the 'boot-comm' system somehow, which I have 
>> not studied. How would I do this?
>
> If you use this now/1 technique, I don't think you'll need the 
> boot-comm system. If you do want to use the boot-comm system, see 
> Vat#seed, which is quite hard to use in a thread-safe manner, or 
> seedVatAuthor.emaker, which is a thread-safe wrapper for Vat#seed.

Ah. I'd forgotten that Vat#seed did the Right Thing.

If I did this, how would I block the external thread until the result 
of a send to the seed-result ref resolves?

>> 2.
>> Set up a Vat running in the original thread. I assume this would 
>> require writing a custom Runner that either stubs out 
>> eventual-sending or implements it on top of the original thread 
>> (which will have its own event loop).
>
> Yes, it would require a custom Runner and RunnerMgr. It would also 
> require adding your RunnerMgr to the Runner#RUNNER_KINDS table.

I thought so. I want to do this such that it works with an unmodified E 
distribution. (Of course this could be changed, but it wouldn't work 
*now*. And using multiple vats instead of an intra-vat bridge is 
arguably the Right Thing.)

>> For this method, how would I set up a Vat on a preexisting Runner?
>
> Given that you've registered your RunnerMgr on RUNNER_KINDS, you'd use 
> the associated runnerKind string as an argument to makeVat.

But in this case, there would not necessarily be only one thread of 
this kind - so putting them in RUNNER_KINDS (if that were to become a 
mutable table) would not be very capability-structured, as it would 
introduce a global namespace. This is really what I meant when I 
mentioned assuming only one thread.

-- 
Kevin Reid                            <http://homepage.mac.com/kpreid/>



More information about the e-lang mailing list