-
-
Notifications
You must be signed in to change notification settings - Fork 415
Fix variable & function thread safety #8285
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
base: dev/patch
Are you sure you want to change the base?
Conversation
|
Thank you for your interest in contributing to Skript! Note that you should target either dev/patch or dev/feature (depending on the PR), instead of master! |
sovdeeth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks for doing this. It's been on the list for a while now but never much of a priority
Have you tested to see if there's any impact to variable access speeds? I wouldn't expect one, but best to be sure.
|
For single-threaded usage, it will have the exact same performance as the write lock can never be held while reading. In theory it would be ever so slightly slower for multi-threaded usage as it would need to wait for writes before checking the queue, but its a negligible difference and necessary to prevent races. Variables always having the correct value is infinitely more important than any loss in performance. |
I know, I'm just curious if it has any measurable impact |
|
wonderful thanks! |






Problem
Calling the same function multiple times from different threads results previously resulted the wrong value being returned. This is now fixed.
Variables were previously not always set to the correct value when multiple threads are modifying unrelated variables at the same time. This is now fixed.
Solution
Testing Completed
This was performed in vanilla Skript and skript-reflect. You can see how the vanilla tests were performed but make use of some uncommon features.
Vanilla tests
Click to view vanilla tests
/test-functionstests that a function will always return the intended value when multiple threads are running the function at the same time./test-variablestests that a variable will always be set to the correct value when multiple threads are modifying unrelated variables at the same time.Steps to run:
/test-functionsand/test-variablesYou must have the following files in your scripts folder

loader.sk
test-functions.sk
test-variables.sk
Outputs
Note: The amount of repetitions were lowered during some of the tests before the changes to limit the responses, but were also tested without changes to the tests.
Before:
After:
Tests written using skript-reflect
/test-reflect-functionstests that a function will always return the intended value when multiple threads are running the function at the same time./test-reflect-variablestests that a variable will always be set to the correct value when multiple threads are modifying unrelated variables at the same time.Outputs
Note: The amount of repetitions were lowered during some of the tests before the changes to limit the responses, but were also tested without changes to the tests.
Before Changes:
After Changes:
Supporting Information
Completes: none
Related: none