-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Atomic symbol resolution: unable to use std/atomics #12695
Comments
…o the drawing board - nim-lang/Nim#12695
Discussing with @Clyybber I realised what was different from my 4 other channels implementation at https://github.com/mratsim/weave/tree/b8ac8d64ca07eb47a926f3f70b96e94fe930cf08/weave/channels. It's the only one using non-instantiated generics. The others uses explicit I can workaround this limitation by using |
This also works: import std/atomics
type
Trivial = SomeNumber | bool | ptr | pointer
MyType* = ptr object
next*: Atomic[MyType]
ChannelFoo*[T: Trivial] = object
front: T
back: Atomic[T]
proc trySend*[T: Trivial](chan: var ChannelFoo[T], src: sink T): bool =
chan.back.store(nil, moRelaxed)
var x = createShared(typeof(default(MyType)[]))
var c = createShared(ChannelFoo[MyType])
let done = c[].trySend(x) EDIT: Actually crashes :( |
Final ugly workaround as I need an Enqueueable concept. import std/atomics
type
MyType* = ptr object
next*: Atomic[MyType]
Trivial = ptr | pointer
Enqueueable = concept x, type T
x is Trivial
x.next is Atomic[T]
ChannelFoo*[T: Trivial and Enqueueable] = object
front: T
back: Atomic[T]
proc trySend*[T: Trivial and Enqueueable](chan: var ChannelFoo[T], src: sink T): bool =
chan.back.store(nil, moRelaxed)
var x = createShared(typeof(default(MyType)[]))
var c = createShared(ChannelFoo[MyType])
let done = c[].trySend(x) Just restraining via concept doesn't workaround the issue. Also "TrySend" must be constrained as well |
Actually I was tricked, that makes the compiler crash without message :/
|
Actually even your solution crashes |
…o the drawing board - nim-lang/Nim#12695
* Stashing: Sadly, we might never know the perf of this channel, back to the drawing board - nim-lang/Nim#12695 * Fix queue, workaround nim-lang/Nim#12695 * Fix fence issue: no strange memory reuse anymore with both Nim and system alloc * Fix #19 #20: Snmalloc / Pony-lang MPSC queues issues: - they hold on the last item of a queue (breaking for steal requests) - they require memory management of the dummy node (snmalloc deletes it and its memory doesn't seem to be reclaimed) - they never touch the "back" pointer of the queue when dequeuing, meaning if an item was last, dequeuing will still points to it. Pony has an emptiness check via tagged pointer and snmalloc does ???
Atomic*[T] = object
when T is Trivial:
value: T.atomicType
else:
nonAtomicValue: T
guard: AtomicFlag If the problem is triggered by |
After #19422 we now get:
With line 338 Nim/lib/pure/concurrency/atomics.nim Lines 337 to 338 in 2bd1aa1
And line 299 Nim/lib/pure/concurrency/atomics.nim Lines 296 to 308 in 2bd1aa1
|
change |
i can reduce this to: type
Foo[T] = object
when T is ptr:
value:T
else:
notvalue:T
proc access[A](self:A) = discard
proc store[T:ptr](self: var Foo[T]) = access(self.value)
#proc store[T:not ptr](self: var Foo[T]) = access(self.notvalue)
type
MyType = ptr object
next: Foo[MyType]
var f:Foo[MyType]
f.store() see the above linked issue for a similar bug Edit: this isn't a completely faithful reduction, as changing 'notvalue' to 'value' doesn't make the compiler hang on 1.6.12 |
type
Foo[T] = object
when T is ptr:
value:T
else:
notvalue:T
proc access[A](self:A) = discard
proc store[T:ptr](self: Foo[T]) = access(self.value)
import macros
macro tk(x: typedesc) =
echo getTypeImpl(x)[1].typeKind
template bar(x: typedesc): untyped =
static:
echo x
echo x is ptr
tk x
x
type
MyType = ptr object
next: Foo[bar(MyType)]
var f:Foo[MyType]
f.store()
|
I manage to reach an atomic dead-end with the long series of symbol resolution issues #8677
The code snippet at the bottom triggers on devel and 1.0.2 the following error messages:
The relevant atomics are:
Nim/lib/pure/concurrency/atomics.nim
Lines 267 to 302 in 78e02d1
Value is defined at line 269, exporting or mixin or bind don't work
The text was updated successfully, but these errors were encountered: