--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Wed, May 14, 2014 at 6:30 AM, James Bardin <j.ba...@gmail.com> wrote:I don't think that's true for a time.Ticker. There will be a
>
> The timer has been designed so that without any references it can be garbage
> collected, once it's been fired.
> This means it either has to wait until the interval triggers a send on its
> internal channel, or you need to call Stop.
reference from the timers variable in runtime/time.goc, so the ticker
will never be garbage collected.
If the Ticker can be garbage collected, then we have a different
problem: a dangling pointer in timers.
Ian
I was not thinking that a goroutine would be killed unconditionally. What I was thinking instead was to provide some mean, such as a function or something, to ask if a send channel has receive ends. Users use it to do whatever it wants. It may want to terminate a goroutine, but it's up to the user.
I was not thinking that a goroutine would be killed unconditionally. What I was thinking instead was to provide some mean, such as a function or something, to ask if a send channel has receive ends. Users use it to do whatever it wants. It may want to terminate a goroutine, but it's up to the user.
2014/05/14 10:43 "Ian Lance Taylor" <ia...@golang.org>:
On Wed, May 14, 2014 at 10:08 AM, Rui Ueyama <ru...@google.com> wrote:
>
> I have an idea that if a goroutine is able to know in some way that all
> receive or bi-directional ends of a send channel have already been garbage
> collected, it can stop sending to the channel and kill itself. Because
> nobody is listening the channel, the goroutine usually want to stop what it
> is doing. It could be like handling SIGPIPE for goroutines.
>
> I'd think it's also useful to prevent goroutine leaking.
We've historically resisted doing that because it can cause large
parts of your program to evaporate with no trace, leaving you with an
empty stack dump and no explanation for where all your goroutines
went.
But perhaps we could capture a stack dump as they go so that we have
something to print if the program crashes.
Ian
--
It would be nice to automatically place any channel that has either no possible senders or no possible receivers into a "broken" state. Then perhaps a runtime function could be provided that creates a special read-only channel that would close whenever the original channel is broken. For example:select {case x <- c:fmt.Printf("%v was read from the channel.\n", x)case _ <- chan.broken(c):fmt.Println("No possible senders on this channel!")}The same would work for sending:select {case c <- x:fmt.Printf("%v was sent on the channel.\n", x)case _ <- chan.broken(c):fmt.Println("No possible receivers on this channel!")}I don't know how hard it would be to implement, but at least I believe it wouldn't break the Go 1 compatibility promise. There are possible variations on this. Maybe a runtime function that takes a channel and returns a modified version of it that treats a broken channel as if it had been closed; thus panicking on write and returning a zero value on read.
ticker := time.NewTicker(duration)
defer ticker.Stop()
Why "broken"? Why not just close the channel?
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/Chx1tCs2QGg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
Would it also be complicated if the channel is blocked in a select? A lone sender goroutine for example could wake up by other means and "create" the receiving goroutine.
15.05.2014 21:33 пользователь "'Rui Ueyama' via golang-nuts" <golan...@googlegroups.com> написал:
>
> By the way I think my concern on this idea is that the existence of GC will change the meaning of the program. GC is usually totally invisible -- it silently reclaim unreferenced values, and whether it exists or not doesn't change the behavior of the program. And that's a good thing. So, if a channel changes its behavior depending on GC's presence, I feel it's a bit weird -- or wrong.
But I feel it right: I want my code to know is there someone who waits for results (or will give some)?
>
> But there are some exceptions there, such as weak references or finalizers. It may be able to be considered as a "weak channel", that returns an error if the other ends are all reclaimed. Well, that's just an idea...
Doesn't "closed channel" exactly matches your "weak channel"?