Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race cond in variabels #523

Merged
merged 3 commits into from
Jan 13, 2024
Merged

Fix race cond in variabels #523

merged 3 commits into from
Jan 13, 2024

Conversation

antonmedv
Copy link
Member

@antonmedv antonmedv commented Jan 13, 2024

Fixes #519

if vm.Scopes != nil {
vm.Scopes = vm.Scopes[0:0]
}
if vm.Variables == nil {
vm.Variables = make([]any, program.variables)
Copy link
Contributor

@sgreben sgreben Jan 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind if you're still working on it, but since I'm on the topic - should the VM be reusable for different programs?

because then i think we need to resize the variables slice here depending on the number of variables in the current program, something like

if cap(vm.Variables) < program.variables { 
    // we need to allocate more in this case
    vm.Variables = make([]any, program.variables) 
} else {
    // we can resize the already-allocated slice
    vm.Variables = vm.Variables[:program.variables] 
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct suggestion. Usually it make sense to only run a vm for a specific program (as we this way stack will be reallocated and potently will not grow)

@antonmedv antonmedv merged commit 523a091 into master Jan 13, 2024
12 checks passed
@antonmedv antonmedv deleted the fix-variables-race branch January 13, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpStore modifies the Program (but shouldn't)
2 participants