I
I
impressive172020-07-19 21:43:08
go
impressive17, 2020-07-19 21:43:08

Is it necessary to lock the structure with a mutex if there is a concurrent write to different fields of the structure?

Is it necessary to lock the structure with a mutex if there is a concurrent write to different fields of the structure?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
montray, 2020-07-19
@quiex

Yes

U
uvelichitel, 2020-07-20
@uvelichitel

None of the built-in types in Go are competitively safe in the language specification. In the current implementation, you can write concurrently to different fields of a pointer-type struct, i.e. an explicit * , map , slice or channel reference. There are no guarantees that such code will not fall in other implementations or on other architectures.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question