heiyeluren / xmm

XMM is a high performance third party memory manager for Go environments that is not affected by Gc and guarantees high performance. XMM是一个在Go语言环境中完全自主实现的第三方内存管理库,不依赖于Go本身的任何内存管理能力,纯自主实现能够应对各种场景下大小内存的 分配/释放 工作,能自主构建高性能的 链表/树/哈希表等各类数据结构,能良好完美的逃逸掉Go内置的GC机制,是构建高性能程序基础设施。
Apache License 2.0
1.12k stars 123 forks source link

Span lock state error when realloc, May overwrite by user's data? #31

Open fly3366 opened 1 year ago

fly3366 commented 1 year ago

package main

import ( "log" "sync" "unsafe"

"github.com/heiyeluren/xmm"

)

func main() { print("Start\n")

f := xmm.Factory{}
m, err := f.CreateMemory(0.6)
if err != nil {
    panic(err)
}

lock := sync.Mutex{}

wg := sync.WaitGroup{}
for i := 0; i < 2; i++ {
    wg.Add(1)

    go func() {
        defer wg.Done()

        for i := 1; i <= 1024; i++ {
            lock.Lock()
            addr, err := m.Alloc(uintptr(i * 4096))
            lock.Unlock()

            if err != nil {
                log.Fatalf("%s", err)
            }

            s := (*[1024 * 4096]byte)(addr)[:uintptr(i*4096):uintptr(i*4096)]

            for idx := range s {
                s[idx] = 255
            }

            lock.Lock()
            err = m.Free(uintptr(unsafe.Pointer(&s[0])))
            lock.Unlock()

            if err != nil {
                panic(err)
            }
        }
    }()
}

wg.Wait()

}

heiyeluren commented 7 months ago

Can you track and check the call logic in the middle of the source code? If any bugs can be found, they can be fixed and a PR can be submitted later. Thank you