Thanks. So I take it this must be handled by the compiler when generating assembly.
E.g. A co-worker pointed out that you can avoid sync.Mutex by using this construct:if !atomic.CompareAndSwapInt32(&s.myLock, 0, 1) {fmt.Println("locked")return}defer atomic.StoreInt32(&s.myLock, 0)processData()Would this synchronise memory?
E.g. A co-worker pointed out that you can avoid sync.Mutex by using this construct:if !atomic.CompareAndSwapInt32(&s.myLock, 0, 1) {fmt.Println("locked")return}defer atomic.StoreInt32(&s.myLock, 0)processData()Would this synchronise memory?
On Monday, 17 August 2020 11:54:55 UTC+1, leo.b...@npo-data.nl wrote:E.g. A co-worker pointed out that you can avoid sync.Mutex by using this construct:if !atomic.CompareAndSwapInt32(&s.myLock, 0, 1) {fmt.Println("locked")return}defer atomic.StoreInt32(&s.myLock, 0)processData()Would this synchronise memory?sync.atomic does synchronise memory, yes.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXKCSHb4-g7uHvf-RMsky8veC52OFDjmguUQCxHDXbShA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/448775D1-7E25-4767-A3D2-08CCC7A68104%40ix.netcom.com.