Exemple #1
0
ANKI_TEST(Util, Threadpool)
{
	const U32 threadsCount = 4;
	const U32 repeat = 5;
	Threadpool* tp = new Threadpool(threadsCount);

	TestJobTP jobs[threadsCount];

	for(U32 i = 1; i < repeat; i++)
	{
		U32 iterations = rand() % 100000;

		for(U32 j = 0; j < threadsCount; j++)
		{
			jobs[j].in = i;
			jobs[j].iterations = iterations;

			tp->assignNewTask(j, &jobs[j]);
		}

		ANKI_TEST_EXPECT_NO_ERR(tp->waitForAllThreadsToFinish());

		for(U32 j = 0; j < threadsCount; j++)
		{
			ANKI_TEST_EXPECT_EQ(jobs[j].in, i + iterations);
		}
	}

	delete tp;
}