Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Provide a guaranteed-lock-free type? #46

Closed
lars-t-hansen opened this issue Jan 23, 2016 · 6 comments
Closed

Provide a guaranteed-lock-free type? #46

lars-t-hansen opened this issue Jan 23, 2016 · 6 comments

Comments

@lars-t-hansen
Copy link
Collaborator

In Issue #7 @jfbastien writes:

From C++ atomic_flag with methods test_and_set and clear says:

Operations on an object of type atomic_flag shall be lock-free. [ Note: Hence the operations should also be address-free. No other type requires lock-free operations, so the atomic_flag type is the minimum hardware-implemented type needed to conform to this International standard. The remaining types can be emulated with atomic_flag, though with less than ideal properties. — end note ]

It may be worth having a similar parallel in SAB. We could require that SAB's atomic_flag be given a 4-byte location and the underlying test_and_set and clear will only touch the bits that the hardware can guarantee as lock-free.

@lars-t-hansen
Copy link
Collaborator Author

In Issue #77, @pizlonator expressed a preference for guaranteed four-byte lock-free access (probably int32, in practice, uint32 being a bit awkward for JS).

@jfbastien
Copy link
Contributor

I think 32-bit values are likely to work on all the HW we target. C++ is overly cautious with atomic_flag by not specifying the size and leaving it up to the implementation to choose the right size for the target. We don't have this leisure of choosing the size once we know the target: we can teach LLVM that 32-bit is wasm's size for atomic_flag but that's it.

@lars-t-hansen
Copy link
Collaborator Author

OK. +1 from me. Proposed spec changes:

  • In the shmem spec, in the section for isLockFree, if n=4 then the implementation always returns true
  • In the agents spec the [[IsLockFree4]] property on the Agents Record is removed with a note added that 4-byte values are always lock free

In reference to my earlier remark above, this would be independent of whether the access type is int32 or uint32, since the atomic operation would only be expressed on a machine word anyhow; any pre/post conversion is immaterial.

@binji, opinions?

@binji
Copy link

binji commented Mar 24, 2016

sgtm, it's hard for me to imagine an architecture that supports SABs where this wouldn't be true.

@lars-t-hansen
Copy link
Collaborator Author

Specs changed and published.

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

No branches or pull requests

4 participants