I read this from the description of threads::shared :
By default, variables are private to each thread, and each newly created thread receives a private copy of each existing variable. This module allows you to exchange variables in different threads ... (more)
Say I have a shared variable like this:
my $var :shared; $var = 10;
This means that the variable exists only once for all the threads that I create.
Now about atomicity and visibility:
If thread_A assigns a new value, say 11:
$var = 11;
Is it guaranteed that thread_B (and all other threads I could create) will see the value 11? And is the task performed atomically?
Or we have, for example, in Java, to first obtain a lock, and then perform an assignment and release a lock. And only threads using the same lock are guaranteed to be able to see the updated value?
Or does it behave like volatile primitive variables in Java?
source share