Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when concurrency alloc #30

Open
fly3366 opened this issue Feb 12, 2023 · 1 comment
Open

Panic when concurrency alloc #30

fly3366 opened this issue Feb 12, 2023 · 1 comment

Comments

@fly3366
Copy link

fly3366 commented Feb 12, 2023

package main

import (
"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)
}

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

	go func() {
		defer wg.Done()

		addr, err := m.Alloc(65535)
		if err != nil {
			panic(err)
		}

		s := (*[65535]byte)(addr)[:65535:65535]

		s[0] = 1

		err = m.Free(uintptr(unsafe.Pointer(&s[0])))
		if err != nil {
			panic(err)
		}
	}()
}

wg.Wait()

}

@heiyeluren
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants