Skip to content

Add configurable limit for Atomics.pause iterations #2047

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

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Jint/Native/Atomics/AtomicsInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private JsValue Pause(JsValue thisObject, JsValue[] arguments)
ExceptionHelper.ThrowRangeError(_realm, "Invalid iteration count");
}

n = System.Math.Min(n, _engine.Options.Constraints.MaxAtomicsPauseIterations);
Thread.SpinWait((int) n);
}
else
Expand Down
5 changes: 5 additions & 0 deletions Jint/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ public class ConstraintOptions
/// The maximum size for JavaScript array, defaults to <see cref="uint.MaxValue"/>.
/// </summary>
public uint MaxArraySize { get; set; } = uint.MaxValue;

/// <summary>
/// How many iterations is Atomics.pause allowed to instruct to wait using <see cref="System.Threading.Thread.SpinWait"/>, defaults to 10 000.
/// </summary>
public int MaxAtomicsPauseIterations { get; set; } = 10_000;
}

/// <summary>
Expand Down