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

Atomics could accept SharedPtr type #17

Open
planetis-m opened this issue Jul 11, 2022 · 1 comment
Open

Atomics could accept SharedPtr type #17

planetis-m opened this issue Jul 11, 2022 · 1 comment

Comments

@planetis-m
Copy link
Contributor

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.

@beef331
Copy link

beef331 commented Aug 24, 2022

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.

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

2 participants