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

stdlib/sync: Match Mutex size with upstream Go #4815

Open
soypat opened this issue Mar 17, 2025 · 3 comments
Open

stdlib/sync: Match Mutex size with upstream Go #4815

soypat opened this issue Mar 17, 2025 · 3 comments

Comments

@soypat
Copy link
Contributor

soypat commented Mar 17, 2025

People are trying to build stuff that uses modernc.org/memory package. There is one assumption made by this package- it requires a size of 8 for sync.Mutex.

The current implementation of sync.Mutex is based on the task.Mutex which is composed of a bool and a Stack (pointer). This gives the Mutex a size of 16 bytes on 64-bit aligned systems while in upstream Go it is 8 bytes.

TinyGo data structures

Go data structures

@aykevl
Copy link
Member

aykevl commented Mar 18, 2025

To be honest, this is a bug in modernc.org/memory, not in TinyGo. They have written non-portable code. If they want to extend portability to TinyGo they could use a build tag. But it's also possible we're going to break this at some point - for example, -scheduler=threads and -scheduler=tasks may have a different sync.Mutex size.

I don't think there's anything to fix on our side.

@aykevl
Copy link
Member

aykevl commented Mar 18, 2025

As it happens, #4559 will make sync.Mutex 8 bytes on a 64-bit system on Linux. It's still no guarantee, but for those looking for a bit more compatibility that PR happens to provide it as a side effect.

@Tryanks
Copy link

Tryanks commented Mar 20, 2025

@soypat
In the commit for libc_issues#43, the allocated memory has been expanded in an attempt to make it compatible with the current tinygo's sync.Mutex. If it works, then this issue seems to have been resolved.

However, after fixing this issue, a new problem has emerged:

i64 add (i64 ptrtoint (ptr @"modernc.org/libc._table" to i64), i64 256)

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

3 participants