Skip to content

Conversation

darkestpigeon
Copy link

Right now when a channel with pending messages is destroyed, a memory leak can occur if the messages themselves have non-trivial destructors. This PR aims to fix this via receiving all the pending messages during channel destruction.
Also adding tryRecv with Option[T} result instead of an out parameter and a boolean flag for convenience.

{.error: "This module requires one of --mm:arc / --mm:atomicArc / --mm:orc compilation flags".}

import std/[locks, isolation, atomics]
import std/[locks, isolation, atomics, options]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah. I don't like options and nothing about this new API is hardly any better than the old one:

var x: T
if tryRecv(chan, x): ...

vs:

let x = tryRecv(chan) 
if x.isSome: ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough

@darkestpigeon
Copy link
Author

Found some apparent problems with the compiler due to this change, distilled and reported them in nim-lang/Nim#24374
Here the =destroy, and hence tryRecv can be called with a wrong type during flushing, which can lead to a segfault or other nasty behaviour.

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

Successfully merging this pull request may close these issues.

2 participants