threading icon indicating copy to clipboard operation
threading copied to clipboard

Atomics could accept SharedPtr type

Open planetis-m opened this issue 3 years ago • 1 comments

Recently someone in the channel has tried to do Atomic[SharedPtr], but it's not currently possible. Of course you don't need the encapsulation, could also use an Atomic[bool] for this. But an idea would be to turn SharedPtr = object to distinct pointer and somehow relax the AtomType type class to accept distinct pointers. I have no idea how that would work.

planetis-m avatar Jul 11 '22 18:07 planetis-m

On planetis' request I'll document a possible solution to this problem:

import std/typetraits
type
  AtomicBases = concept a, type A
    distinctBase(A) is AtomType
  AllAtomTypes = AtomType or AtomicBases
  Atomic*[T: AllAtomTyps] = distinct T

This should allow all types that are actually capable of being atomic to be as such, though i guess one might want to ensure that the T itself is not atomic, but I do not know anything about threading.

beef331 avatar Aug 24 '22 08:08 beef331