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

Add x_get_lock, synchronized changes #1381

Merged
merged 6 commits into from
Apr 12, 2024
Merged

Add x_get_lock, synchronized changes #1381

merged 6 commits into from
Apr 12, 2024

Conversation

LadyCailin
Copy link
Member

Provide a new function, x_get_lock, which provides an asynchronous lock waiting mechanism. This uses the same underlying lock structure as synchronized(). Additionally, the lock object has now been restricted to non-value types, except strings. This is a breaking change, but is unlikely to affect anyone.

This function works in coordination with sychronized(), to provide a
more flexible solution when coordinating between main thread tasks and
custom thread tasks. When using sychronized() on the main thread, this
is very dangerous, and can very easily lead to deadlocks when using
x_run_on_main_thread_now within the secondary thread, which is a common
pattern. x_get_lock provides an automated mechanism to help balance
these concerns, and automates return of control to the main thread, and
a backoff, so that deadlocks become far easier to avoid.

This works in conjunction with the same lock pool as synchronized(), but
it is changed to use a ReentrantLock object, rather than the native java
synchronized() operator.
@LadyCailin LadyCailin merged commit a019b99 into master Apr 12, 2024
3 of 4 checks passed
@LadyCailin LadyCailin deleted the x_get_lock branch April 12, 2024 23:03
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.

1 participant