Self

 Calling Sequence Self()

Description

 • The Self command returns the threads identifier of the current thread.
 • For the main thread, the thread identifier is always 0.  For other threads, the thread identifier is an integer greater than 0.

Examples

 > $\mathrm{id}≔\mathrm{Threads}:-\mathrm{Create}\left(\mathrm{print}\left(\mathrm{Threads}:-\mathrm{Self}\left(\right)\right)\right)$
 ${\mathrm{id}}{≔}{1}$ (1)
 > $\mathrm{Threads}:-\mathrm{Wait}\left(\mathrm{id}\right)$
 > $n≔5$
 ${n}{≔}{5}$ (2)
 > t := table(); p := proc( t )     t[ Threads:-Self() ] := 1; end proc;
 ${t}{≔}{table}{}\left(\left[\right]\right)$
 ${p}{:=}{\mathbf{proc}}\left({t}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{t}{[}{\mathrm{Threads}}{:-}{\mathrm{Self}}{}\left({}\right){]}{:=}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (3)
 > $s≔\left[\mathrm{seq}\left(\mathrm{Threads}:-\mathrm{Create}\left(p\left(t\right)\right),i=1..n\right)\right]$
 ${s}{≔}\left[{2}{,}{3}{,}{4}{,}{5}{,}{6}\right]$ (4)
 > $\mathrm{Threads}:-\mathrm{Wait}\left(\mathrm{op}\left(s\right)\right)$
 > $\mathrm{indices}\left(t\right)$
 $\left[{2}\right]{,}\left[{3}\right]{,}\left[{4}\right]{,}\left[{5}\right]{,}\left[{6}\right]$ (5)