Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

Update thread-safe implementation for GameFiles#1

Open
nguyenlamlll wants to merge 1 commit intoRonenNess:masterfrom
nguyenlamlll:patch-1
Open

Update thread-safe implementation for GameFiles#1
nguyenlamlll wants to merge 1 commit intoRonenNess:masterfrom
nguyenlamlll:patch-1

Conversation

@nguyenlamlll
Copy link

Locking on the value of a private static variable to prevent thread-safety violations and performance issues.

Locking on the value of a private static variable to prevent thread-safety violations and performance issues.
@RonenNess
Copy link
Owner

I'll take a look when I'll have time, probably during the next weekend..
Thanks!

@RonenNess
Copy link
Owner

OK overall this seems like an harmless change, but could you explain a bit what problem it solves and how is this improving performance? Thanks!

@nguyenlamlll
Copy link
Author

I haven't looked at the full engine yet but so far what I've found and based on what I've experienced, the previous version implemented a non-safe singleton pattern. We may try to multi-thread saving some game files in the future so these changes ensure that.
If there isn't a lock, 2 or more threads can jump into a single if statement providing they bypass the check but haven't created an instance.
I'm sorry if this is quite trivial.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants