// deThreadTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "..\deNet\deThreadPool.hpp"

DWORD test1( void * p )
{
	int i = 0;

	printf( "deNet thread test1 -- \n" );

	for( i=0; i<1000; i++ )
	{
		/*
		for( int j=0; j<10; j++ )
		{
			char c[10];
			itoa( j*i/3+3*3, c, 10 );

			for( int k=0; k<j; k++ )
			{
				
			}
		}
		*/
		int q = 234&23*13+1/2;
	}

	printf( "deNet thread test1 -- DONE! DONE!\n" );
	return 0;
}

DWORD test2( void * p )
{
	int i = 0;

	printf( "deNet thread test2 -- \n" );

	for( i=0; i<1000; i++ )
	{
		/*
		for( int j=0; j<10; j++ )
		{
			
		}

		char c[10];
		itoa( j*i/3+3*3, c, 10 );

		for( int k=0; k<j; k++ );
		*/
		
		int q = 234&23*13+1/2;
	}

	printf( "deNet thread test2 -- DONE! DONE!\n" );
	return 0;
}

int main(int argc, char* argv[])
{

	// quick thread test

	int i = 0;	

	deThreadPool * pool = deNet_GetThreadPool();

	printf( "Starting Application Now.\n" );

	pool->CreateThreads( 2 );

	for( i=0; i<100; i++ )
	{
		// sleep 10 ms
		Sleep( 10 );
		if( i % 2 )
		{
			pool->ActivateIdleThread( test1, NULL, 0, NULL, false );
		}
		else
		{
			pool->ActivateIdleThread( test2, NULL, 0, NULL, false );
		}
	}

	printf( "\n\n*** Application is now waiting... ***\n\n" );
	Sleep( 8000 );
	
	pool->DestroyAllThreads(false);

	return 0;
}

