RT ..
import (
"fmt"
"sync"
)
var g_pMutex *sync.Mutex
var g_iCount int32
func Test_Mutex() {
Logger.Debug( "Test_Mutex Beg" )
defer Logger.Debug( "Test_Mutex End" )
fmt.Println( "" )
g_pMutex = new( sync.Mutex )
Logger.Debugf( "g_pMutex=0X%X", &g_pMutex )
g_iCount = 0
pfnFunc := func ( pMutex *sync.Mutex ) {
Logger.Debug( "TestUse Beg" )
defer Logger.Debug( "TestUse End" )
Logger.Debugf( "pMutex=0X%X", &pMutex )
pMutex.Lock()
defer pMutex.Unlock()
g_iCount ++
}
pfnFunc( g_pMutex )
}
结果如下
![333.png](http://studygolang.qiniudn.com/160817/14d7fd63b37462ef06c45112bc8a52cb.png)
为啥 外面的 g_pMutex 和pfnFunc := func ( pMutex *sync.Mutex ) 函数内的pMutex 地址不同。
有疑问加站长微信联系(非本文作者)