[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-dev] Interpreter Locks
On 11/7/06, Ryan Brown <ryan@xxxxxxxxx> wrote:
I've run into a pretty serious problem and I'm wondering if anyone
has a solution. Essentially I want to call Supercollider using
runInterpreter() even though gLangMutex is locked.
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.
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
SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
[anInvocation setTarget: doc];
[anInvocation setSelector: sel];
[scvm defer: anInvocation];
This comes up in
my bridge (see my previous post if you don't what I'm talking about)
when an Objective-C method is called from Supercollider which then
tries to send a message to an Objective-C subclass in Supercollider.
Here is what happens:
1- Some code which calls Objective-C is executed in the interpreter
(i.e. window.display where window is an NSWindow). [MyDocument
executeSelection:] is called which calls interpretPrintCmdLine in SC.
To call interpretPrintCmdLine a lock is taken out.
2- Eventually the Objective-C method is called which then sends a
message to a proxy object representing a Supercollider class.
3- The proxy object receives the message and tries to forward it
along to SC, but gLangMutex is locked so it deadlocks.
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?
--- james mccartney