#include <fstream>
#include <kernel>
#include <stdlib>
#include <thread>

// thread First;
// void main(First* this);

// thread Second;
// void main(Second* this);

thread First  { signal_once* lock; };
thread Second { signal_once* lock; };

void ?{}( First * this, signal_once* lock ) { this->lock = lock; }
void ?{}( Second * this, signal_once* lock ) { this->lock = lock; }

void main(First* this) {
	for(int i = 0; i < 10; i++) {
		sout | "First : Suspend No." | i + 1 | endl;
		yield();
	}
	signal(this->lock);
}

void main(Second* this) {
	wait(this->lock);
	for(int i = 0; i < 10; i++) {
		sout | "Second : Suspend No." | i + 1 | endl;
		yield();
	}
}


int main(int argc, char* argv[]) {
	signal_once lock;
	sout | "User main begin" | endl;
	{
		processor p;
		{
			First  f = { &lock };
			Second s = { &lock };
		}
	}
	sout | "User main end" | endl;
}