User guide

18-3
ThreadBegin; // Thread 1
y = x'x;
z = y'y;
ThreadEnd;
ThreadBegin; // Thread 2
q = r'r;
r = q'q;
ThreadEnd;
ThreadStat n = m'm; // Thread 3
ThreadStat p = o'o; // Thread 4
ThreadJoin; // waits for Threads 1-4 to finish
b = z + r + n'p; // Using the results
18.2 GAUSS Threading Concepts
This is really the one and only thing you need to know about threads:threadsaresep-
aratesectionsofthesameprogram,executingsimultaneously,operatingonthesame
data.Infact,it'ssofundamentalit'sworthsayingagain:threadsareseparatesectionsof
codeinaprogram,runningatthesametime,usingthesameworkspace,referencingand
operatingonthesamesymbols.
Thisraisesbasicissuesofworkflowanddataintegrity.Howdoyoumanagethecreation
andexecutionofthreads,andmakeuseoftheworktheydo?Andhowdoyoumaintain
dataintegrity?(You do notwanttwothreadsassigningtothesamesymbolatthesame
time.)
Tohandlethreadworkflow,GAUSSemploysasplit-and-joinapproach.Atvarious
pointsinyourprogram(asmanyasyoulike),youdefineasetofthreadsthatwillbe
createdandrunasagroup.Whencreated,thethreadsinthesetexecutesimultaneously,
eachdoingusefulwork.Theparentthreadwaitsforthecreatedthreadstocomplete,
thencontinues,theresultsoftheirworknowavailableforfurtheruse.
Tomaintaindataintegrity,weintroducethewriter-must-isolate(informally,the any-
thread-can-read-unless-some-thread-writes)programmingrule.Thatistosay,sym-
bolsthatarereadfrombutnotassignedtocanbereferencedbyasmanythreadsinaset
asyoulike.Symbolsthatareassignedto,however,mustbe whollyownedbyasingle
Multi-Threaded
Programming