lock: flock with timeout support
I like FlockMutex because it work on kernel level and is reliable.
however there’s the problem that acquiring the lock makes program wait forever. I wish to get error “unable to obtain lock withing timeout”
for flock there’s LOCK_NB
flag which can be used.
ps: SemaphoreMutex has similar issue
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (14 by maintainers)
Commits related to this issue
- Add PcntlTimeout utility class PcntlTimeout::timeBoxed() can be used to put timeouts on system calls like flock(). This class works only in UNIX with enabled pcntl extension. It should not be used in... — committed to php-lock/lock by malkusch 8 years ago
- Add PcntlTimeout utility class PcntlTimeout::timeBoxed() can be used to put timeouts on system calls like flock(). This class works only in UNIX with enabled pcntl extension. It should not be used in... — committed to php-lock/lock by malkusch 8 years ago
- #6 Timeout for FlockMutex — committed to php-lock/lock by willemstuursma 6 years ago
- #6 Improve test coverage for FlockMutex — committed to php-lock/lock by willemstuursma 6 years ago
- Update documentation regarding #6 — committed to php-lock/lock by willemstuursma 6 years ago
Timeout support has been added to
FlockMutex
in themaster
branch.It uses PCNTL if possible and busy waiting if not.
It’s not production ready! But is’t ready for some testing. Please report any issues here.
Having a timeout is actually a nice feature.
LOCK_NB
would turn the implementation into a busy waiting lock and suffer from being inacurate. I will consider this option as a last resort. But first I will see ifpcntl_alarm
might be a better option. However:This won’t be a low hanging fruit.