shithub: mc

ref: 655dad8f92c315c5c205b3c021b19ce2916e4c9b
dir: /lib/thread/test/mutex.myr/

View raw version
use std
use thread

use thrtestutil

const Nherd = 20

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

const main = {
	mtx = thread.mkmtx()
	done = thread.mkwg(Nherd)

	thrtestutil.mkherd(Nherd, incvar)
	thread.wgwait(&done)
	if val != 1000 * (Nherd : uint64)
		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.wgpost(&done)
}