...ing logging 4.0

はてなブログに移行しました。D言語の話とかいろいろ。

thread

import std.thread;
import std.cstream;

void main()
{
	string a = "A", b = "B";
	Thread thA = new Thread(&thread, cast(void*)a);
	Thread thB = new Thread(&thread, cast(void*)b);
	thA.start();
	thB.start();
	thA.wait();
	thB.wait();
	
	dout.puts("");
	
	Thread thX = new MyThread("X");
	Thread thY = new MyThread("Y");
	thX.start();
	thY.start();
	thX.wait(); 
	thY.wait(); 
}

int thread(void* p)
{
	for (int i=0; i<10; ++i)
		dout.writef("%s ", *cast(char*)(p)).flush();
	return 0;
}

class MyThread : Thread
{
	private string s_;
	this(string s)
	{
		s_ = s;
	}
	override int run()
	{
		for (int i=0; i<10; ++i)
			dout.writef("%s ", s_).flush();
		return 0;
	}
}