Concurrent computing: Difference between revisions

Added XPL0 example.
m (→‎{{header|c sharp|C#}}: Regularize header markup to recommended on category page)
(Added XPL0 example.)
Line 2,200:
Enjoy
Code
</pre>
 
=={{header|XPL0}}==
Works on Raspberry Pi using XPL0 version 3.2. Processes actually execute
simultaneously, one per CPU core (beyond single-core RPi-1). Lock is
necessary to enable one line to finish printing before another line starts.
<lang XPL0>int Key, Process;
[Key:= SharedMem(4); \allocate 4 bytes of memory common to all processes
Process:= Fork(2); \start 2 child processes
case Process of
0: [Lock(Key); Text(0, "Enjoy"); CrLf(0); Unlock(Key)]; \parent process
1: [Lock(Key); Text(0, "Rosetta"); CrLf(0); Unlock(Key)]; \child process
2: [Lock(Key); Text(0, "Code"); CrLf(0); Unlock(Key)] \child process
other [Lock(Key); Text(0, "Error"); CrLf(0); Unlock(Key)];
Join(Process); \wait for all child processes to finish
]</lang>
 
{{out}}
<pre>
Code
Enjoy
Rosetta
</pre>
 
772

edits