Skip to content

Concerned use of 'static int cache' can break multiple VM instances #552

@ewmailing

Description

@ewmailing

This was discussed in #547. Even though we are spending a bunch of time on a separate issue in that discussion, I am concerned this one is still an issue, so I want to file it so it doesn't get lost.

In the generated code from coder.lua, there are places that static variables are used for cache purposes.

        static int cache = -1;
        TValue *slot = pallene_getstr(9, x9, tsvalue(&K->uv[16].uv), &cache);

My concern is that if these values are not constant for all cases except maybe for some global one-time initialization, this could cause bugs and break user programs if they use multiple Lua VMs in their program. I don't fully understand what is being cached and the side effects of everything, but it raises alarm bells for me.

I was specifically thinking of Lua Lanes, which will have multiple instances of Lua VMs running concurrently across multiple threads. But I am concerned that even having just two different VMs that you run one after another could still potentially lead the second VM instance to pick up the static int cached value set from the prior first VM run instance, and maybe that cached value is now wrong for this second instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions