同步访问同一变量

I want to make sure that my update function is executed only by one thread at a time for a given value.

func update1(int id){
   ...
   makeUpdate(id)
   ...
}

func update2(int id){
   ...
   makeUpdate(id)
   ...
}

So, how should I write my makeUpdate() function that the myUpdate block is executed only once for a given id value? That means if update1 is updating the record with the id "15" and update2 with the id "20", the block access should not be synchronized.

As comments suggest - you need to protect data access not functional access.

Easiest way to achieve this, is to make a struct type with a lock - and attach the critical functional update as a method e.g.

type MyData struct {
        l sync.Mutex
        // add any other task related attributes here too
}

// makeUpdate *MUST* use a pointer to our struct (i.e. 'm *MyData')
// as Mutex logic breaks if copied (so no 'm MyData')
func (m *MyData) makeUpdate(id int) {
        m.l.Lock()
        defer m.l.Unlock()

        fmt.Printf("better makeUpdate(%d)
", id) 

        // do critical stuff here

        // don't dilly-dally - lock is still being used - so return quickly
}

Try this out in the playground.