On Monday, 5 June 2017 18:11:00 UTC+3, Chun Zhang wrote: > > Unfortunately it does not give any info. :( >
Can you upload the code somewhere? Other ideas: 1. set environment variable GODEBUG to cgocheck=2 2. try valgrind - maybe it picks something up (not sure how well it works) 3. try sanitizers - search `go build -msan`... I've never used it, but you can see some tests for it in https://github.com/golang/go/tree/master/misc/cgo/testsanitizers Other than that, yeah... try to get the example as small as possible and so that you can show it. + Egon > Thanks, > Chun > > On Saturday, June 3, 2017 at 1:16:18 PM UTC-4, Egon wrote: >> >> Does race detector say something useful? >> >> On Friday, 2 June 2017 21:18:31 UTC+3, Chun Zhang wrote: >>> >>> I am trying to store some complicated data structure with a map, and >>> eventually search and use it. >>> Since the structure can change with different applications, and it has >>> to work with multiple thread, I defined a generic map like follows >>> >>> type IndexedMap struct { >>> sync.RWMutex >>> DataNode map[interface{}]interface{} >>> } >>> >>> Insert is defined as >>> >>> func (m *IndexedMap) Insert(dataIndex interface{}, data interface{}) error { >>> >>> var err error >>> >>> m.Lock() >>> >>> //if the node exist >>> if _, ok := m.DataNode[dataIndex]; ok { >>> m.Unlock() >>> return m.Update(dataIndex, data) >>> } else { >>> //insert new node >>> m.DataNode[dataIndex] = data >>> } >>> >>> m.Unlock() >>> >>> return err >>> } >>> >>> >>> ** For now, the data being inserted is a structure, not the pointer to >>> the structure and the key/index is a string.** >>> >>> >>> Then when I need to find a piece of data, I tried to get a snapshot of >>> the database first and then look for it >>> >>> v, ok : = m.SnapShotData()[key] where >>> >>> func (m *IndexedMap) SnapShotData() map[interface{}]interface{} { >>> >>> ret := make(map[interface{}]interface{}) >>> >>> m.Lock() >>> for k, v := range m.DataNode { >>> ret[k] = v >>> } >>> m.Unlock() >>> >>> return ret >>> } >>> >>> >>> Then the data v is used to do other things, never modified though. >>> >>> This works but the performance is abysmal when the database getting >>> large. So, I tried to search without copying >>> >>> v, ok := m.DataSearch(key) >>> >>> func (m *IndexedMap) DataSearch(dataIndex interface{}) (interface{}, bool) { >>> >>> var data interface{} >>> var ok bool >>> >>> m.Lock() >>> >>> data, ok = m.DataNode[dataIndex] >>> >>> m.Unlock() >>> >>> return data, ok >>> } >>> >>> >>> >>> However, with this implementation, I always get crash after running the >>> program just a little bit with the following error >>> >>> *** Error in `./colordecoder': double free or corruption (fasttop): >>> 0x00007f943c26f590 *** >>> SIGABRT: abort >>> PC=0x7f946c2eac37 m=4 >>> signal arrived during cgo execution >>> >>> I guess somewhere along the line the copy is a not a hard copy but just >>> a reference copy. However, I couldn't understand the difference between >>> above two approaches, seems that in SnapShotData I did exactly the same >>> thing, but no crash ever. >>> >>> Can somebody tell me where I did wrong? Thanks!! >>> >>> >>> -- 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.