> I guess I dont understand why you would want the lock entirely for the 
> entire execution of the function until the defer.

You can get the effect of block-scoped defers by using a local anonymous
function:

    func f(a *A) {
        func() {
            a.mu.Lock()
            defer a.mu.Lock()
            do_stuff_with_a_locked(a)
        }()
        do_stuff_with_a_unlocked(a)
    }

Perhaps more convincing:

    func f(as []A) {
        for _, a := range as {
            func() {
                a.mu.Lock()
                defer a.mu.Unlock()
                do_stuff(a)
            }()
        }
    }

-- Juliusz

            

-- 
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