Re: [go-nuts] Stack based slice usage and unsafe

2019-05-26 Thread Sergey Kamardin
Hello Ian, Thank you for your answer. On Sun, 05/26/19, May 26, 2019 at 07:59:07PM -0400, Ian Lance Taylor wrote: > This is not valid. The rule is that SliceHeader is only valid when > inspecting an actual slice header. You have to write > > h.Data = uintptr(unsafe.Pointer(&b)) > h.Len

Re: [go-nuts] Interesting public commentary on Go...

2019-05-26 Thread 'Axel Wagner' via golang-nuts
This is a bit of an aside, I agree with everything Ian said, but: On Thu, May 23, 2019 at 7:59 PM Ian Lance Taylor wrote: > If a language is to change over time, this specification or > implementation must change. Somebody has to decide how changes will > be made. All successful languages have

Re: [go-nuts] Stack based slice usage and unsafe

2019-05-26 Thread Ian Lance Taylor
On Sun, May 26, 2019 at 11:30 AM Sergey Kamardin wrote: > > func ReadHeader(r io.Reader) (Header, error) { > var ( > b [16]byte > bts []byte > ) > h := (*reflect.SliceHeader)(unsafe.Pointer(&b

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Dan Kortschak
Please don't. Java is not relevant here and the advice given by other prior to this post in the thread is not incorrect. Using atomic operations (in this case it would be atomic.Value's Load and Store methods) invokes a write barrier, which is fundamentally just a memory synchronisation. In pkg syn

[go-nuts] tcell clear screen - first char disapears

2019-05-26 Thread pythonnilo
Hello Gophers, I'm playing with tcell, but I found a strange problem when I try to clear the screen. I wrote the code on gist: https://gist.github.com/lskbr/9fc28e999ad414edfaf8aef07eb316a9 The code that clear the screen is commented out. When it is used, the screen is cleared, but the first c

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread roger peppe
On Sun, 26 May 2019 at 19:17, Jan Mercl <0xj...@gmail.com> wrote: > On Sun, May 26, 2019 at 8:05 PM Sotirios Mantziaris > wrote: > > > From what i understand you propose to create a new object and switch out > the old one with the new one using the atomic package of go. > > That cannot work. Stri

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Robert Engels
And for the OP, there are atomics defined for strings - so what I referred you to is still valid. > On May 26, 2019, at 4:21 PM, Robert Engels wrote: > > I said nothing to the contrary. I was referring to the structures the poster > discussed - which are not heap allocated within an array whic

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Robert Engels
I said nothing to the contrary. I was referring to the structures the poster discussed - which are not heap allocated within an array which differs from Java objects. I think you would be better served by doing more reading and listening and less yelling. > On May 26, 2019, at 3:25 PM, Wojci

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Wojciech S. Czarnecki
On Sun, 26 May 2019 13:50:13 -0500 Robert Engels wrote: > This is an advantage that Java offers over Go for concurrent programming. > Since everything is reference you don’t face this distinction. Which is why > most Go uses channels, which are implemented with locks. It would be good and fruitf

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Robert Engels
* especially > On May 26, 2019, at 1:51 PM, Robert Engels wrote: > > Using atomics, which is what I stated to do, avoids the data race and is Edie > sully useful with weak atomics. > >> On May 26, 2019, at 1:37 PM, Sotirios Mantziaris >> wrote: >> >> I was thrown of by the previous comment.

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Sotirios Mantziaris
Thanks for the clarification Robert. On Sunday, May 26, 2019 at 9:50:56 PM UTC+3, Robert Engels wrote: > > I was referring to updating a reference to a string, which can be updated > atomically. > > This is an advantage that Java offers over Go for concurrent programming. > Since everything is

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Robert Engels
Using atomics, which is what I stated to do, avoids the data race and is Edie sully useful with weak atomics. > On May 26, 2019, at 1:37 PM, Sotirios Mantziaris > wrote: > > I was thrown of by the previous comment. > I think i will create some "atomic" types that handle using mutexes with >

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Robert Engels
I was referring to updating a reference to a string, which can be updated atomically. This is an advantage that Java offers over Go for concurrent programming. Since everything is reference you don’t face this distinction. Which is why most Go uses channels, which are implemented with locks.

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Sotirios Mantziaris
I was thrown of by the previous comment. I think i will create some "atomic" types that handle using mutexes with setter and getter methods. Thanks Jan On Sunday, May 26, 2019 at 9:17:44 PM UTC+3, Jan Mercl wrote: > > On Sun, May 26, 2019 at 8:05 PM Sotirios Mantziaris > > wrote: > > > From wha

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Jan Mercl
On Sun, May 26, 2019 at 8:05 PM Sotirios Mantziaris wrote: > From what i understand you propose to create a new object and switch out the > old one with the new one using the atomic package of go. That cannot work. String is a multi word value. There's nothing in the atomic package that can upd

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Sotirios Mantziaris
>From what i understand you propose to create a new object and switch out the old one with the new one using the atomic package of go. If that is the case i cannot use it since i don't control the field directly. I am using the SetString method of the Value struct in the reflect package. // SetS

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Robert Engels
Ignore the incorrect comments from the others. There are many valid cases where relaxed concurrency rules apply and you don’t need synchronization just atomic ops (and with certain platform this is not needed - eg java volatile)That is why GC systems can outperform non GC systems in concurrent s

Re: [go-nuts] Re: Stack based slice usage and unsafe

2019-05-26 Thread Sergey Kamardin
Hi Peter, Thank you for your answer. Actually it is not so – please see the rule (6) of the unsafe package documentation: https://golang.org/pkg/unsafe/ -- Regards, Sergey. On Sun, 05/26/19, May 26, 2019 at 09:43:13AM -0700, peterGo wrote: > Sergey Kamardin, > > Your code is invalid. A uintpt

[go-nuts] Re: Stack based slice usage and unsafe

2019-05-26 Thread peterGo
Sergey Kamardin, Your code is invalid. A uintptr variable is an integer, not a pointer. type SliceHeader: https://golang.org/pkg/reflect/#SliceHeader SliceHeader is the runtime representation of a slice. It cannot be used safely or portably and its representation may change in a later release.

Re: [go-nuts] Any alternative to go-bindata that supports dynamic assets?

2019-05-26 Thread Sam Whited
On Sun, May 26, 2019, at 13:44, Mark Bauermeister wrote: > Is there any alternative that would allow loading the files > dynamically during development and baking them into the source upon > release? Or am I better off just writing some custom logic that simply > tries to load the file from the fil

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Sotirios Mantziaris
I understand, i have to synchronize access... Coming from another language i had some guarantees on some assignments mostly int. A string might be a issue here of course... I have to refactor my code in order to make is safe. thanks. On Sunday, May 26, 2019 at 6:13:56 PM UTC+3, Jan Mercl wrote:

Re: [go-nuts] Stack based slice usage and unsafe

2019-05-26 Thread Jan Mercl
On Sun, May 26, 2019 at 5:30 PM Sergey Kamardin wrote: I'm not sure what the goal is, but the code looks like doing the same as just `bts := b[:]`. But then it's equal to just `bts := make([]byte, 16)`. Remember, there si no stack nor heap wrt the language specification, so there is no guaranteed

[go-nuts] Stack based slice usage and unsafe

2019-05-26 Thread Sergey Kamardin
Hello gophers, I have a question which relates mostly to the ideology of unsafe usage. In `github.com/gobwas/ws` WebSocket library I used an optimization for reading WebSocket frame headers into stack based slices (to reduce the number of heap allocations): func ReadHeader(r io.Reader)

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Wojciech S. Czarnecki
On Sun, 26 May 2019 07:03:35 -0700 (PDT) Sotirios Mantziaris wrote: > Let's assume that the string field Name has the value `Mr. Smith` and we > change this to `Mr. Anderson` in the goroutine, what are the possible > values that i could bet on a read? > If these are either `Mr. Smith` or `Mr.

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Jan Mercl
On Sun, May 26, 2019 at 4:03 PM Sotirios Mantziaris wrote: > Let's assume that the string field Name has the value `Mr. Smith` and we > change this to `Mr. Anderson` in the goroutine, what are the possible values > that i could bet on a read? > > If these are either `Mr. Smith` or `Mr. Anderso

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Sotirios Mantziaris
Let's assume that the string field Name has the value `Mr. Smith` and we change this to `Mr. Anderson` in the goroutine, what are the possible values that i could bet on a read? If these are either `Mr. Smith` or `Mr. Anderson` i am very ok with that because i want the value to be eventually co

Re: [go-nuts] Data race question in config package of harvester

2019-05-26 Thread Jan Mercl
On Sun, May 26, 2019 at 3:45 PM Sotirios Mantziaris wrote: > Is there a chance that reading and assigning values might not be atomic? Accessing a the full multi word value is non-atomic on most, if not all architectures. -- You received this message because you are subscribed to the Google Gro

[go-nuts] Re: Any alternative to go-bindata that supports dynamic assets?

2019-05-26 Thread Mark Bauermeister
Actually. To answer my own question, this probably suffices for most/all of my use cases. func LoadScript(script string) { L := lua.NewState() defer L.Close() file, err := Asset(script) if err = L.DoFile(script); err != nil { L.DoString(string(file)) } } On Sunday,

[go-nuts] Data race question in config package of harvester

2019-05-26 Thread Sotirios Mantziaris
i am working on a library for configuration named harvester( https://github.com/taxibeat/harvester), which will be soon properly open sourced, where i can dynamically reconfigure the configuration from an outside system (consul). The user provides a struct with some tags type testConfig struct

[go-nuts] Any alternative to go-bindata that supports dynamic assets?

2019-05-26 Thread Mark Bauermeister
My use case is a game engine that uses Lua scripts. Naturally, Lua scripts can be changed during runtime without rebuilding the entire project. Since go-bindata doesn't actually load the file during runtime but merely precompiles it to a string representation, it doesn't work for dynamic conten