Remaining threads failure with contexts

Andrew Whitworth wknight8111 at
Sun Sep 9 13:30:01 UTC 2012

Tadzik found a problem with threads and lexicals, which exposes a
larger problem with threads. Here's shortened winxed code to

function main[main](var args)
    var x = 5;
    var t = new 'Task'(function() { say(x); });
    ${schedule t};
    ${wait t};

And here's the assertion failure I get when I run on a debug build:

src/call/context_accessors.c:283: failed assertion
'ctx->vtable->base_type == enum_class_CallContext'
Backtrace - Obtained 17 stack frames (max trace depth is 32).
/lib/x86_64-linux-gnu/ [0x7f05860bae9a]
/lib/x86_64-linux-gnu/ [0x7f05868c04bd]
Attempting to get PIR backtrace.  No guarantees.  Here goes...
current instr.: 'main' pc 20 ((file unknown):23) (test.winxed:6)
called from Sub '__PARROT_ENTRY_WINXED_main' pc 1381 (ext/winxed/driver.pir:484)
Aborted (core dumped)

The problem is conceptually very simple: For cross thread access we're
wrapping the callcontext in a Proxy PMC. However, some optimized code
in the system (specifically in src/call/context_accessors.c and
src/sub.c) assert the existence of a CallContext PMC only (not a
proxy) and perform direct data access on those PMCs. Unfortunately
those direct accesses create problems because the PMC type we've got
is a Proxy not a CallContext.

Switching over the direct accesses to use vtable calls instead of
direct accesses will tank performance. We've seen that before. I
suspect that adding in too many checks for CallContext/Proxy and
switching behaviors for those accesses will also be bad for

The lexicals problem that Tadzik found is only one small part of this
problem. Any time we've got a Proxied CallContext, we're going to run
into problems.

One solution I can think of now is to create a local clone of a
CallContext whenever we find a Proxy instead. LexPad and LexInfo
appear to work just fine when proxied so we only need a very shallow
clone. This creates a problem where modifications to the proxied
parent context will be made to the clone instead of the original. I
don't know how big a problem this is, but I suspect it will be small.

I'm out most of the afternoon so I'll have time to think about this
more. Any other ideas and suggestions are welcome.

--Andrew Whitworth

More information about the parrot-dev mailing list