In the previous article, we looked at using mutexes to synchronize access to shared data.
V provides syntactic sugar for this using
shared variables and
Under the hood,
shared variables are structs with an additional hidden mutex that is used to
synchronize data access.
Shared variables must be structs, arrays, or maps!
Such variables can be passed as arguments to other functions and threads, in which case they need to
be passed as
Receivers can also be marked as
Accessing shared variables data
To access the data of
shared variables, blocks
lock for reading/writing and
rlock for reading
Outside them, access to data is prohibited.