diff options
author | Steve Bennett <steveb@workware.net.au> | 2019-07-29 13:28:31 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2019-07-31 08:46:01 +1000 |
commit | c8abda4d473268842201f228b8980e523766e91b (patch) | |
tree | e8563fd0694c51885bf0e4f504049c55c50e0f41 /tests/lock.test | |
parent | a8b8c416c7f3c9e06fe3320b25e8dd37570e9f92 (diff) | |
download | jimtcl-c8abda4d473268842201f228b8980e523766e91b.zip jimtcl-c8abda4d473268842201f228b8980e523766e91b.tar.gz jimtcl-c8abda4d473268842201f228b8980e523766e91b.tar.bz2 |
aio: Add support for lock -wait
Sometimes it is useful to wait for a lock to become available.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests/lock.test')
-rw-r--r-- | tests/lock.test | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/lock.test b/tests/lock.test index 3672d6a..e7b0b2d 100644 --- a/tests/lock.test +++ b/tests/lock.test @@ -42,6 +42,19 @@ test lock-1.5 {grab lock from sub-process} { set stat } 0 +test lock-1.6 {wait for lock} { + # Run a child process that grabs the lock for 0.5 seconds + set pid [exec [info nameofexecutable] -e {set fh [open locktest.file r+]; $fh lock; sleep 0.5} >/dev/null &] + # And wait to acquire the lock in the parent. Should take ~500ms + set start [clock millis] + sleep 0.1 + $fh lock -wait + set delta [expr {[clock millis] - $start}] + if {$delta < 100} { + error "Lock acquired after ${delta}ms" + } +} {} + $fh close file delete locktest.file |