Skip to content

Make lock object in ControlFlowInstructions.Compile private#287

Merged
slozier merged 1 commit intoIronLanguages:mainfrom
BCSharp:no_lock_this
Feb 20, 2026
Merged

Make lock object in ControlFlowInstructions.Compile private#287
slozier merged 1 commit intoIronLanguages:mainfrom
BCSharp:no_lock_this

Conversation

@BCSharp
Copy link
Copy Markdown
Member

@BCSharp BCSharp commented Feb 19, 2026

Using lock (this) exposes the lock to external callers. If it is meant to be used internally, it should be locking on a private object. If it is used as a part of public (or protected) API, it should be documented explicitly, because it is not visible from just looking at the public/protected methods. Also, locking on this does not allow for different choice of type for the lock object, so generally is not a good idea.

ControlFlowInstructions uses it only for private purpose, to ensure it is compiled only once. This PR fixes that locking.

Unfortunately, CustomStringDictionary also does lock (this), but it is a public abstract class, so locking this is already part of the established public usage spec of this class and changing it would be a breaking API change. Therefore CustomStringDictionary is not changed.

Copy link
Copy Markdown
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

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

Thanks!

@slozier slozier merged commit 259b382 into IronLanguages:main Feb 20, 2026
8 checks passed
@BCSharp BCSharp deleted the no_lock_this branch February 20, 2026 06:22
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.

2 participants