Concurrent computing: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (BaCon and BBC BASIC moved to the BASIC section.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(One intermediate revision by one other user not shown)
Line 1,059:
 
=={{header|Java}}==
Create a new <code>Thread</code> array, shuffle the array, start each thread.
<syntaxhighlight lang="java">
Thread[] threads = new Thread[3];
threads[0] = new Thread(() -> System.out.println("enjoy"));
threads[1] = new Thread(() -> System.out.println("rosetta"));
threads[2] = new Thread(() -> System.out.println("code"));
Collections.shuffle(Arrays.asList(threads));
for (Thread thread : threads)
thread.start();
</syntaxhighlight>
<br />
An alternate demonstration
{{works with|Java|1.5+}}
Uses CyclicBarrier to force all threads to wait until they're at the same point before executing the println, increasing the odds they'll print in a different order (otherwise, while the they may be executing in parallel, the threads are started sequentially and with such a short run-time, will usually output sequentially as well).
Line 2,214 ⟶ 2,226:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
 
var words = ["Enjoy", "Rosetta", "Code"]
9,476

edits