Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f8d59febe2
Fetching contributors…

Cannot retrieve contributors at this time

23 lines (17 sloc) 0.608 kb
import printer.(println);
import sequences.(map);
import threads.(startThread, joinThread);
import threads.locks.(Spinlock, Synchronized, synchronized, synchronizedLoad);
var counter = Synchronized[UInt, Spinlock](0u);
counterThread() {
for (x in range(1000))
synchronized(counter, c -> {c +: 1;} );
}
main() {
// spawn eight threads, each of which increments counter 1000 times
// using a spinlock for synchronization
var threads = map(x -> startThread(counterThread), range(8));
for (thread in threads)
joinThread(thread);
println(synchronizedLoad(counter));
}
Jump to Line
Something went wrong with that request. Please try again.