Skip to content

complete the implementation of std.mutex on all platforms #1455

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

Closed
shawnl opened this issue Sep 2, 2018 · 5 comments
Closed

complete the implementation of std.mutex on all platforms #1455

shawnl opened this issue Sep 2, 2018 · 5 comments
Labels
standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@shawnl
Copy link
Contributor

shawnl commented Sep 2, 2018

As threads can be suspended at any time (even kernel threads!), we need not just spinlocks, but blocking locks implemented with futexes and their equivalent. This is necessary to fix #1363

https://www.kernel.org/doc/Documentation/robust-futexes.txt
http://man7.org/linux/man-pages/man2/futex.2.html
http://man7.org/linux/man-pages/man7/futex.7.html
https://www.akkadia.org/drepper/futex.pdf

@shawnl shawnl closed this as completed Sep 2, 2018
@andrewrk andrewrk reopened this Sep 2, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Sep 2, 2018
@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Sep 2, 2018
@andrewrk andrewrk changed the title Futexes, and equilivent syscall-backed locking (user-space) complete the implementation of std.mutex on all platforms Sep 2, 2018
@shawnl
Copy link
Contributor Author

shawnl commented Sep 2, 2018

Lock must be the same struct on all architectures so they can be shared between heterogeneous processes. Use-case: https://keithp.com/blogs/Shared_Memory_Fences/

Because musl and glibc do not do this correctly we can't be compatible with them. (although they could become compatible with us in the future)

@kristate
Copy link
Contributor

kristate commented Sep 2, 2018

WebKit guys have their ParkingLot implementation.

@shawnl
Copy link
Contributor Author

shawnl commented Sep 2, 2018

in regards to "Concurrent Hashtable of Synchronized Queues" of the ParkingLot blog post: I am wondering how much spin-lock contention a concurrent red-black tree has, because that would eliminate out-of-memory and dynamic memory allocation in ParkingLot as the the rb-node could be stored on the stack. https://xuezhaokun.github.io/150-algorithm/

Also, it would allow WTF::Lock-type locks to be shared between processes. (through multiple instances of WTF::ParkingLot)

Wouldn't perform as well on NUMA systems however...

shawnl added a commit to shawnl/zig that referenced this issue Sep 3, 2018
see ziglang#1455

Eventually I would like to see something like WTF::Lock/WTF::ParkingLot,
but that is a bunch of work.
@andrewrk
Copy link
Member

andrewrk commented Sep 3, 2018

Lock must be the same struct on all architectures so they can be shared between heterogeneous processes

When a user wants a lock that is the same struct on all architectures or whatever, they should explicitly request it by using a type that makes this guarantee. The default std lib mutex should not make this guarantee.

@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Mar 1, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 May 9, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Oct 17, 2019
@andrewrk
Copy link
Member

I believe this is done now, thanks to @kprotty's work. If not, please open separate issues for each OS that is not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants