shithub: mc

ref: 814c5bcd2efc3bb9139a56a1e0eae177437f4f56
dir: /lib/thread/test/atomic.myr/

View raw version
use std
use thread

use thrtestutil

const Nherd = 20

var val : uint64 = 0
var done : uint32 = 0

const main = {
	done = 0
	val = 0
	thrtestutil.mkherd(Nherd, incvar)
	while thread.xget(&done) != Nherd
		/* nothing */
	;;
	std.assert(val == 2_000_000, "atomics are broken\n")
}

const incvar = {
	var i

	for i = 0; i < 100_000; i++
		thread.xadd(&val, 1)
	;;
	thread.xadd(&done, 1)
}