Re: [go-nuts] Hesitating on using cached / un-cached channels

2022-04-11 Thread burak serdar
An unbuffered channel is a synchronization mechanism. A send on an unbuffered channel will block until there is a concurrent receive from another goroutine. Your program has only one goroutine. A send to an unbuffered channel will always deadlock, so will a receive from it. So the problem you are

Re: [go-nuts] Hesitating on using cached / un-cached channels

2022-04-11 Thread robert engels
There are numerous ways to create a “dead lock” in any program (this may actually be a “live lock” but I didn’t fully understand your statement - this is just one of them. > On Apr 11, 2022, at 9:29 PM, Zhaoxun Yan wrote: > > Hi guys, I have a great demonstration on why an un-cached channel

[go-nuts] Re: Is it possible to change the existing printline dynamically in golang?

2022-04-11 Thread Zhaoxun Yan
Thanks a log Amnon! :D 在2022年4月1日星期五 UTC+8 21:25:14 写道: > Yes, this is the murky world of ANSI escape codes. > Fortunately there are a whole load of libraries which do this for you... > Try https://github.com/cheggaaa/pb > or https://github.com/schollz/progressbar > or

[go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-11 Thread Zhaoxun Yan
The scenario is upon receiving an incoming financial quotation, save it as a string of json into a Redis service. Sorry but I cannot provide the whole code of quotation receiving here, which is very complex with cgo. But the code below will help you get a glimpse on what should be going on:

[go-nuts] Hesitating on using cached / un-cached channels

2022-04-11 Thread Zhaoxun Yan
Hi guys, I have a great demonstration on why an un-cached channel might malfunction while receiving: package main import( "fmt" "time" ) func main(){ t := time.NewTicker(time.Second * 3) stopnow := make(chan bool) //stopnow := make(chan bool, 1) //cached channel

Re: [go-nuts] why the opendefer optimization will close when my function's named return value escape

2022-04-11 Thread Ian Lance Taylor
On Thu, Apr 7, 2022 at 11:03 AM ワタナベハルキ wrote: > > GOARCH="amd64" > GOHOSTOS="linux" > GOVERSION="go1.17.2" > > Here is my test code > > var sink *int > > func main(){ > escape() > } > > // named return value r > func escape() (r int) { > defer func(){ > recover() > }() >

Re: [go-nuts] Why does infinitely-recursing code not give stack overflow in Playground?

2022-04-11 Thread Sam Hughes
I've hit this problems a few times, and I immediately thumbs-upped that issue report. To correct @Ben, I suggest the purest reasoning for an error being displayed is "The process completed, and did not succeed". In your case, @Ben, yeah, it was killed while waiting on something, but the normal

Re: [go-nuts] Why does infinitely-recursing code not give stack overflow in Playground?

2022-04-11 Thread ben...@gmail.com
> Depending on implementation, infinite recursion is not guaranteed to blow > the stack for the program given. The function call is in tail position, so > a tail-call optimization (TCO) pass would be able to rewrite the program > into an infinite loop by reusing the existing stack frame for

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-11 Thread Santiago Corredoira
I tried with a more complex application and already got constant 100% CPU usage twice. When I attach strace I see the same as with the minimal demo but with much more frecuency: [pid 42659] 23:36:49.035120 epoll_pwait(3, [], 128, 0, NULL, 140341803388040) = 0 [pid 42659] 23:36:49.035133

Re: [go-nuts] Re: [security] Go 1.18.1 and Go 1.17.9 pre-announcement

2022-04-11 Thread Carlos Amedee
Yes, we are still scheduled to release Go 1.18.1 and 1.17.9 on Tuesday April 12. Carlos On Monday, April 11, 2022 at 3:26:17 PM UTC-4 dav...@gmail.com wrote: > Carlos, Julie, > > Are we still on for tomorrow? (golang 1.18.1 specifically) Please let us > know (from k8s side, we are eagerly

Re: [go-nuts] Re: [security] Go 1.18.1 and Go 1.17.9 pre-announcement

2022-04-11 Thread Davanum Srinivas
Carlos, Julie, Are we still on for tomorrow? (golang 1.18.1 specifically) Please let us know (from k8s side, we are eagerly waiting! [1]) thanks in advance, Dims [1] https://groups.google.com/a/kubernetes.io/g/leads/c/4tFb3pOq3g0/m/payrHytjCgAJ On Thu, Apr 7, 2022 at 12:12 PM Carlos Amedee

Re: [go-nuts] Dynamically loading custom passes with gollvm?

2022-04-11 Thread 'Than McIntosh' via golang-nuts
Hello, At the moment gollvm doesn't support anything like the "-Xclang -load -Xclang ...". It would not be too hard to add this though. Want to send a patch? Thanks, Than On Sun, Apr 10, 2022 at 3:47 PM Balamurugan Marimuthu wrote: > Yes, something like that! I basically want to run my

Re: [go-nuts] Why does infinitely-recursing code not give stack overflow in Playground?

2022-04-11 Thread Jesper Louis Andersen
On Wed, Apr 6, 2022 at 3:18 AM ben...@gmail.com wrote: > Normally the Go Playground gives errors when a runtime panic or other > error occurs, including "timeout running program" for programs that run too > long. I'm wondering why the Playground doesn't show a stack overflow error > (or any

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-11 Thread Santiago Corredoira
I tried with the stripped tmp version of "go run" and after a while I was able to reproduce it too. It definitely took me more time but probably is just random. I tried "$ GODEBUG=asyncpreemptoff=1 ./test" and I kept seeing the the calls every 10ms. Is this expected to happen? I compiled the

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-11 Thread Brian Candler
On Monday, 11 April 2022 at 09:26:28 UTC+1 scorr...@gmail.com wrote: > and the output keeps growing like that with every new curl request until > eventually it starts constantly printing output like this: > >> >> [pid 143818] 10:02:22.697120 nanosleep({tv_sec=0, tv_nsec=1000}, >> NULL) = 0

Re: [go-nuts] float exactness

2022-04-11 Thread Sam Hughes
Noting that what @Brian%20Candler just said is bang on, I'll add that if you use `math.Nextafter(y, math.Round(y))` or `y - math.Nextafter(math.Mod(y, 0.01), math.Round(y))`, you can clean up a poorly represented number. The following is Brian's example, but with those two algorithms

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-11 Thread Santiago Corredoira
I discovered this in another very similar pc, a bit older Lenovo Legion laptop: $ grep "model" /proc/cpuinfo | sort | uniq -c 12 model: 158 12 model name: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz $ uname -r 5.4.0-107-generic $ cat /etc/*ease DISTRIB_ID=LinuxMint

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-11 Thread Santiago Corredoira
Hi Brian, thanks for your help. Al my go downloads are from go.dev In this tests I am using $ go version go version go1.18 linux/amd64 I run the tests in a laptop with linux as the main OS, no emulation. $ grep "model" /proc/cpuinfo | sort | uniq -c 12 model: 165 12 model

[go-nuts] Re: YAML Unmarshal changes keys

2022-04-11 Thread vika...@gmail.com
Thanks a ton for the explanation and for helping to fix the issue. I will keep the yaml library in mind. On Monday, 11 April 2022 at 15:44:58 UTC+10 sam.a@gmail.com wrote: > I skipped over to that package, and the doc says it converts from yaml to > json, and the marshals/unmarshals. I

Re: [go-nuts] float exactness

2022-04-11 Thread Brian Candler
According to the go spec : "Constant expressions are always evaluated exactly; intermediate values and the constants themselves may require precision significantly larger than supported by any predeclared type in the language" Hence there's

Re: [go-nuts] Structured configuration in Go

2022-04-11 Thread Sam Hughes
@Paul%20Jolly, me likey! There's a really clean tokenizer implementation, and if nothing else that's really nice baseline to mimic! On Sunday, April 10, 2022 at 5:36:18 AM UTC-5 Andrew Pillar wrote: > > I think there are two big advantages to making your application > > consume either plain JSON

[go-nuts] Re: Constant CPU usage on an idle HTTP server from Go 1.17

2022-04-11 Thread Brian Candler
Those nanosleep calls are at 10ms intervals - i.e. 100 calls per second. I think this is normal behaviour of the Go scheduler, which signals itself every 10ms to force a preemptive context switch. That feature was introduced in go 1.14, at which point you were able to disable it at runtime