Re: [go-nuts] Re: How to wait for specified amount of time in a loop without timer overhead
Maybe you could investigate something like this: https://www.snellman.net/blog/archive/2016-07-27-ratas-hierarchical-timer-wheel/ Disclaimer: I've not tried that method, but I saw it recently and filed it away as potentially useful -- Ian On Thu, Aug 4, 2016, at 11:14 AM, pi wrote: > You mean something like this? > > func (b *RingBuf) ReadWait(min uint32, timeout time.Duration) bool { > if min == {min = 1}if b.ReadAvail() >= min { > return true}if timeout.Nanoseconds() == {return false > }const pollPeriod = 100 * time.Nanosecondniter := > int64(timeout.Nanoseconds() / pollPeriod.Nanoseconds()) > > for i := int64(); i < niter; i++ {if b.ReadAvail() >= min { > return true}time.Sleep(pollPeriod) } return false } > >> I think it would be cheaper to call time.Sleep than spinning on >> runtime.Gosched. > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: How to wait for specified amount of time in a loop without timer overhead
You mean something like this? func (b *RingBuf) ReadWait(min uint32, timeout time.Duration) bool { if min == 0 { min = 1 } if b.ReadAvail() >= min { return true } if timeout.Nanoseconds() == 0 { return false } const pollPeriod = 100 * time.Nanosecond niter := int64(timeout.Nanoseconds() / pollPeriod.Nanoseconds()) for i := int64(0); i < niter; i++ { if b.ReadAvail() >= min { return true } time.Sleep(pollPeriod) } return false } I think it would be cheaper to call time.Sleep than spinning on > runtime.Gosched. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: How to wait for specified amount of time in a loop without timer overhead
I think it would be cheaper to call time.Sleep than spinning on runtime.Gosched. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.