[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] Interpreter Locks



You can't. If this were allowed it would be possible to have a call
stack like this:
runInterpreter->C primitive->runInterpreter. If the nested call were
to yield from a coroutine there would be a problem because it might
have to yield up through the primitive.

You mean if the initial runInterpreter was made within a Routine and then the second runInterpreter tried to yield? I think it would be more reasonable to ban doing this (when using the Cocoa bridge) than to ban making calls that needed to call back on SC.


What you have to do is package up a deferred call like the following
to your own object, and your object can call runInterpreter:

		SEL sel = @selector(closeWindow);
NSMethodSignature *sig = [MyDocument instanceMethodSignatureForSelector: sel];

		NSInvocation *anInvocation = [NSInvocation
invocationWithMethodSignature: sig];
		SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
		[anInvocation setTarget: doc];
		[anInvocation setSelector: sel];
		[scvm defer: anInvocation];

This won't work because the original call from the interpreter is waiting for a return value. If it is defered then the primitive calling Objective-C won't be able to get a return value because the call won't be made until after the lock is released. I could implement something where you get the return value after making a call, but that would be ugly.

Is it possible to create a copy of the current state of the VM
(stack, thread contexts, etc.), call runInterpreter() and then
restore the VM to the saved state?

no.

I tried doing a memcpy of gVMGlobals and then restoring it after calling runInterpreter, and it works (which was surprising) but is unstable. After a while (5 minutes or so?) the object that runInterpreter called gets garbage collected despite it being black and having reference (from the environment dictionary). Why do you say this isn't possible? Is it just the coroutine issue or are there other reasons?

Thanks for your help,
Ryan