[ create a new paste ] login | about

Link: http://codepad.org/K4xQOREZ    [ raw code | output | fork ]

D, pasted on May 5:
import std.stdio;
import std.conv;
import core.thread;
import core.sync.condition;
import core.sync.mutex;

Condition[4] cv;

void output(int Idx)() {
	cv[Idx - 1] = new Condition(new Mutex());
	for (;;) {
		cv[Idx - 1].wait();
		write(to!char(Idx));
		Thread.sleep(dur!("msecs")(500));
		static if (Idx != 4)
			cv[Idx].notify();
		else
			cv[0].notify();
	}
}

void main() {
	auto tg = new ThreadGroup();
	tg.create(&output!1);
	tg.create(&output!2);
	tg.create(&output!3);
	tg.create(&output!4);
	Thread.sleep(dur!("seconds")(1));
	cv[0].notify();
	tg.joinAll();
}


Output:
1
2
3
4
5
6
7
Line 13: found '!' when expecting ','
Line 13: found '(' when expecting '.' following 'char'
Line 13: found ')' when expecting ';' following 'statement'
Line 24: found '!' when expecting ','
Line 25: found '!' when expecting ','
Line 26: found '!' when expecting ','
Line 27: found '!' when expecting ','


Create a new paste based on this one


Comments: