On Wed, Apr 26, 2017 at 5:47 PM Юрий Соколов <funny.fal...@gmail.com> wrote:

> > Don't Lock without defer Unlock(). (I'm a sinner, just telling what I
learned.)
>
> You are not quite right. Sometimes there is scope dependency between Lock
and Unlock, ie Unlock happens not at function exit, but is triggered
asynchronously
by some condition.
More: if you panic cause you already found state inconsistent, then there is
no way to fix it, cause most likely you don't know how it became
inconsistent.

My lesson learned includes that Unlock before returning from the function
that did the Lock is the only safe-by-design form of using a mutex. In
other cases channel is probably a better choice.



-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to