This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
 BUILT-IN MATHEMATICA SYMBOL See Also »| More About »

# SetSharedVariable

 SetSharedVariable declares the symbols as shared variables whose values are synchronized among all parallel kernels.
• The unique value of a shared variable is maintained by the master kernel and every access on a parallel subkernel is synchronized through the master kernel.
• Shared variables without a value evaluate to Null.
Make xs be a (global) shared variable:
Each subkernel increments the (global) shared variable value:
Without sharing, each subkernel has its own (local) copy of the variable:
Make xs be a (global) shared variable:
Each subkernel increments the (global) shared variable value:
 Out[2]=
 Out[3]=
Without sharing, each subkernel has its own (local) copy of the variable:
 Out[5]=
 Out[6]=
 Scope   (4)
Share a single value:
Access a single element of a shared list efficiently:
Assign a new value to a shared variable:
Only the last assignment performed remains:
Change a single element of a shared list:
Update the value of a shared variable:
Append to a shared list:
Append to an element of a shared list:
Delayed values defined on the master kernel are evaluated on the master kernel:
Delayed values defined on a subkernel are evaluated on the kernel asking for the value:
 Applications   (5)
Use shared variables to synchronize input and output in an infinite search:
Find such that is prime, until the computation is manually aborted:
Use a shared variable to signal all evaluations to stop as soon as a prime has been found:
Use a shared variable to hand out tasks to do:
Monitor the progress of a calculation, counting major calculation steps:
Return results as they are found:
Watch the results appear in real time:
\$KernelCount is effectively a shared variable:
Separate read and write operations are not thread-safe:
Use atomic updates for synchronization:
Alternatively, use CriticalSection to make a whole code section atomic:
New in 7