Hello,

This is a passage in book <The Go Programming Language>:
--------------------------------------------------------------------------------------------------------
There is a good reason Go’s mutexes are not re-entrant.

The purpose of a mutex is to ensure that certain invariants of the shared 
variables are
maintained at critical points during program execution.

One of the invariants is "no goroutine is accessing the shared variables", 
but there may be additional invariants specific to the data structures that 
the mutex guards.

When a goroutine acquires a mutex lock, it may assume that the invariants 
hold. While it holds the lock, it may update the shared variables so that 
the invariants are temporarily violated.

However, when it releases the lock, it must guarantee that order has been 
restored
and the invariants hold once again.

Although a re-entrant mutex would ensure that no other goroutines are 
accessing the shared variables, it cannot protect the additional invariants 
of those variables.
 
--------------------------------------------------------------------------------------------------------

This passage is difficult for me to understand:
1. How to understand invariants "invariants"?
2. What kind of scenarios does “additional invariants” refer to?
3. What is the relationship between "shared variables" and "invariants"?
4. What does "...guarantee that order has been restored..." mean?

Thanks,
Guanyun

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b732271d-4bd5-47d7-bdfc-9c4c612b63e1n%40googlegroups.com.

Reply via email to