Skip to content

Commit

Permalink
throw error when locking / unlocking is not symmetric, add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed May 7, 2015
1 parent 05f5afe commit d2fe03f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/lock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ unlock(o::Any) = unlock(o.lock)

function unlock(rl::ReentrantLock)
rl.reentrancy_cnt = rl.reentrancy_cnt - 1
if rl.reentrancy_cnt < 0
error("unlock count must match lock count")
end
if rl.reentrancy_cnt == 0
rl.locked_by = nothing
notify(rl.cond_wait)
elseif rl.reentrancy_cnt < 0
AssertionError("unlock count must match lock count")
end
rl
return rl
end

7 changes: 7 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,10 @@ immutable NoMethodHasThisType end
warning_str = readall(`$exename -f -e $script`)
@test contains(warning_str, "f()")
end

# lock / unlock
let l = ReentrantLock()
lock(l)
unlock(l)
@test_throws ErrorException unlock(l)
end

0 comments on commit d2fe03f

Please sign in to comment.