

#include <iwear/thread.h>
#include <iwear/threadlocker.h>
#include <iwear/exceptions.h>

#include <iostream>

using namespace std;
using namespace iwear;

class UThread: public Thread {
    public:
	void Run( void )
	{
//	    cout << "Im running" << endl;
	    while(true) usleep(100000000);
	}
};

int main ( void )
{
    std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
    putenv("IWEAR_NO_GSTACK");

    uint32_t i;
    try 
    {
	for(i = 0; i < 15000; ++i )
	{
//	    cout << "allocating thread " << i << endl;
	    Thread* t = new UThread();
	    cout << "\rStarting new thread " << i << flush;
	    t->Start();
	    pthread_yield();
	}
    }
    catch( const exception& e )
    {
	cout << endl;
	cout << "Threads Creation Exception: " << endl;
	cout << e << endl;
    }
    cout << "Max Threads:" << i << endl;

    try 
    {
	new ThreadLocker(0);
    }
    catch( const exception& e )
    {
	cout << "Thread Locker New:" << endl;
	cout << e << endl;
    }
    
//    usleep(1000000000);
}
