Skip to content

proposal: atomic keyword #14977

Closed
Closed
@OneOfOne

Description

@OneOfOne
  • disclaimer: I'm horrible at writing essays and proposals, so take this with a grain of salt.

Abstract

With the growing number of processor cores, many developers use atomics rather than mutex/cond when they can.

Background

For primitive types, we have sync/atomic, which provides Load/Store/Swap/CAS, however, for other types we only have atomic.Value, which only provides Load/Store and the added overhead of runtime type assertion since it uses interface{}

Proposal

Here comes the atomic keyword (more like chan, but it can be something else really):

v := make(atomic *SomeStruct)
ov := v.Swap(&SomeStruct)
if v.CompareAndSwap(nil, &SomeStruct) { }

v2 := v.Load()
v.Store(v3)
// or maybe?
v2 := v // implicit v.Load()?
v := v3 // implicit v.Store(v3)

Implementation

It'd be implemented much like atomic.Value internally, probably using a spinlock for CAS and Swap operations, with the added runtime magic to handle types directly instead of using interface{}.

Ideas? Feedback?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions