Re: [go-nuts] Inconsistency in GC behavior depending on runtime.Goexit

2025-04-14 Thread 'Michael Knyszek' via golang-nuts
I dug into your example and I think I see two problems. The first problem is that `S` gets allocated in the tiny allocator, and so its lifetime may get batched together with something long-lived. This creates some inconsistent behaviors in the non-Goexit case. (I have an experimental debug mode

Re: [go-nuts] Inconsistency in GC behavior depending on runtime.Goexit

2025-04-09 Thread Yaroslav Brustinov
Thanks for the explanation! I ended up ignoring cleanup checks if test failed (=> runtime.Goexit() is called) IMHO it's somewhat counter-intuitive that after calling runtime.Goexit() something is still held... On Friday, April 4, 2025 at 7:18:32 AM UTC+3 Robert Engels wrote: > And as Sean point

Re: [go-nuts] Inconsistency in GC behavior depending on runtime.Goexit

2025-04-03 Thread Robert Engels
And as Sean pointed out, the reason it is never run is that the object being cleaned up is still referenced (I didn’t verify this)On Apr 3, 2025, at 5:28 PM, Yaroslav Brustinov wrote:I was sure the doc means the case when a program exits too quickly, before cleanup has a chance to run, or am I wr

Re: [go-nuts] Inconsistency in GC behavior depending on runtime.Goexit

2025-04-03 Thread Robert Engels
I think you are misreading it. It is a semicolon which means both clauses are of equal rank. So the sentence is referring to when they run, and they may not run at all, and there is no guarantee that they run before program exit - some systems have exit actions that are always attempted to run befo

Re: [go-nuts] Inconsistency in GC behavior depending on runtime.Goexit

2025-04-03 Thread robert engels
It states this in the API docs: "The cleanup(arg) call is not always guaranteed to run; in particular it is not guaranteed to run before program exit." > On Apr 3, 2025, at 10:23 AM, Yaroslav Brustinov wrote: > > Hello, experts. > > Given following code as example: > > package main > > impo

Re: [go-nuts] Inconsistency in GC behavior depending on runtime.Goexit

2025-04-03 Thread 'Sean Liao' via golang-nuts
Your value of `s` may be on the stack rather than the heap. Cleanup will run when it goes out of scope, which is when the function returns. Your deferred function where you're trying to check is preventing that. You can force heap allocation, or check after the functions return. Your two cases beh

Re: [go-nuts] Inconsistency in GC behavior depending on runtime.Goexit

2025-04-03 Thread Yaroslav Brustinov
I was sure the doc means the case when a program exits *too quickly,* before cleanup has a chance to run, or am I wrong? Otherwise, why need to specify "not guaranteed to run before program exit."? It obviously can't run after program exits :) In the code example above, I can wait indefinitely f

[go-nuts] Inconsistency in GC behavior depending on runtime.Goexit

2025-04-03 Thread Yaroslav Brustinov
Hello, experts. Given following code as example: package main import ( "fmt" "io" "runtime" "sync/atomic" "time" ) type S struct { foo int } var released1 atomic.Bool var released2 atomic.Bool func releaseCb(releaseFlag *atomic.Bool) { fmt.Println("release CB") releaseFlag.Store(true) } func