Skip to content

Locked timeout#35

Closed
bstanescu wants to merge 4 commits intophp-lock:masterfrom
bstanescu:feature/locked-timeout
Closed

Locked timeout#35
bstanescu wants to merge 4 commits intophp-lock:masterfrom
bstanescu:feature/locked-timeout

Conversation

@bstanescu
Copy link

@bstanescu bstanescu commented Oct 7, 2019

Spinlock with a twist (pun intended 😉)

Problem:
I needed to throw an exception if the lock is already taken, but only after a given timeout.

Proposed solution
The spinlock already has its own timeout (eg: 5 seconds). With this new option: lockedTimeout you can now specify a timeout while lock is already taken. (eg: 3 seconds).
The process will try to acquire the lock for 3 seconds then throw an exception if it doesn't succeed.

If we specify a lockedTimeout of 0, the exception will be thrown immediately after the first lock acquire attempt.

This (with a lockedTimeout of zero) also addresses:
#21 (comment)

@willemstuursma willemstuursma force-pushed the master branch 4 times, most recently from 50b6d7f to 81e0882 Compare February 18, 2020 13:33
@willemstuursma
Copy link
Contributor

Thanks. So you want to have a different timeout for acquiring the lock and the maximum lock execution, correct?

I think we should name the two locks then $acquisitionTimeout and $executionTimeout.

@willemstuursma
Copy link
Contributor

Could you update all the files to change the naming, I'll have a better look in the coming days.

@pablomoreno61
Copy link

this PR seems pretty interesting, is it still alive? Long time without any update on it...

@mvorisek
Copy link
Member

mvorisek commented Dec 10, 2024

Thanks to #72 two timeouts are newly supported - aquire timeout ("locked timeout" terminology used here) and expire timeout.

The advantage of the new AbstractSpinlockWithTokenMutex class is the expire timeout is not only used on client side, but also on server side, preventing never-expiring deadlocks.

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.

5 participants