shithub: mc

ref: 01d9c59aa0f27db7bd3b9b8c1978c9a65c5e60a0
dir: /lib/thread/test/mutex.myr/

View raw version
use std
use thread

use thrtestutil

const Nherd = 20

var val : uint64 = 0
var done : uint32 = 0
var mtx : thread.mutex

const main = {
	done = 0
	val = 0

	mtx = thread.mkmtx()
	thrtestutil.mkherd(Nherd, incvar)
	while thread.xget(&done) != Nherd
		/* nothing */
	;;
	if val != 1000 * 20
		std.fatal("mutexes are broken, got {}\n", val)
	;;
}

const incvar = {
	for var i = 0; i < 1000; i++
		thread.mtxlock(&mtx)
		val++
		thread.mtxunlock(&mtx)
	;;
	thread.xadd(&done, 1)
}