Ejemplo n.º 1
0
void testThreadsRunningAndTerminating() {
	// ONE stopped, TWO stopped
	IThread *one = new ThreadSimple();
	IThread *two = new ThreadSimple();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() == 0);
	assert(!two->isActive());
	assert(ThreadHolder::getActiveThreads() == 0);

	// ONE started, TWO started
	one->start();
	two->start();

	assert(one->getId() != 0);
	assert(one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 2);

	Sleep(USUAL_DELAY);

	// ONE stopped, TWO started
	one->terminate();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 1);

	Sleep(USUAL_DELAY);

	// ONE started, TWO started
	one->start();

	assert(one->getId() != 0);
	assert(one->isActive());
	assert(two->getId() != 0);
	assert(two->isActive());
	assert(ThreadHolder::getActiveThreads() == 2);

	Sleep(USUAL_DELAY);

	// ONE stopped, TWO stopped
	one->terminate();
	two->terminate();

	assert(one->getId() == 0);
	assert(!one->isActive());
	assert(two->getId() == 0);
	assert(!two->isActive());
	assert(ThreadHolder::getActiveThreads() == 0);

	delete one;
	delete two;
}
Ejemplo n.º 2
0
	static void *(entry_point)(void *_this)
	{
		IThread *self = static_cast<IThread<T, U> *>(_this);

		self->setStatus(Running);
		self->_func_ptr(self->getId(), self->getParameter());
		self->setStatus(Stopped);
		MutexVault::getMutexVault()->remove(self->getId());
		return (NULL);
	}
Ejemplo n.º 3
0
IThread *ThreadHolder::current()
{
	init();

	IThread * thread = m_currentThread;
	if (thread == NULL)
		return DummySphereThread::getInstance();

#ifdef _WIN32
	ASSERT(thread->getId() == ::GetCurrentThreadId());
#else
	ASSERT(thread->getId() == (unsigned)pthread_self());
#endif
	return thread;
}