This is documentation for Mathematica 7, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

CriticalSection

CriticalSection[{var1, var2, ...}, expr]
locks the variables vari with respect to parallel computation, evaluates expr, then releases the vari.
  • At most one instance of a critical section with the same lock variable is allowed to run concurrently on any parallel kernel.
  • Variables used as locks should not have a value in the master kernel.
Unsynchronized reading and writing access to a shared variable gives wrong results:
The code between reading and writing xs should be run sequentially to avoid interference:
Unsynchronized reading and writing access to a shared variable gives wrong results:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
 
The code between reading and writing xs should be run sequentially to avoid interference:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
New in 7