V
V
Vladimir Grabko2016-06-01 19:46:16
go
Vladimir Grabko, 2016-06-01 19:46:16

How does blocking work?

If I have 1000 routines that are trying to read / write data to the map and for locks, I use sync. It turns out that 1 routine reads / writes, while others are waiting? Is the execution queue of routines guaranteed (for example, the web server keeps online and the routines are launched at different times, then they must also be executed in the order in which they were set). Right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gizmothron, 2016-06-01
@VGrabko

The fact that you are using sync means nothing - be specific, there are many functions/objects in sync.
The sequence may coincide, but it is not guaranteed at all if you do not explicitly arrange it yourself.
Yes, all are blocked and waiting for one to read/write if you use sync.Mutex.
In general, when reading, you do not need to block. Use the special sync.RWMutex.
You need to block for a very small number of operations.
If there are many/complex operations, then use channels instead of sync.
You can also read to use lock-free algorithms, for this you need the atomic package.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question