Utility class to execute code in a separate execution thread.
- Deprecated:
- Use Boost.Thread
Example:
#include <test.h>
#include <lunchbox/clock.h>
#include <lunchbox/sleep.h>
#include <lunchbox/thread.h>
#include <iostream>
#define NTHREADS 256
{
public:
virtual ~LoadThread() {}
};
class InitThread : public LoadThread
{
public:
InitThread() : initLeft( false ) {}
virtual ~InitThread() {}
{
initLeft = true;
return true;
}
{
}
bool initLeft;
};
class FailThread : public InitThread
{
public:
virtual ~FailThread() {}
{
return false;
}
};
int main( int, char** )
{
LoadThread loadThreads[NTHREADS];
for( size_t i=0; i<NTHREADS; ++i )
TEST( loadThreads[i].
start( ));
for( size_t i=0; i<NTHREADS; ++i )
TEST( loadThreads[i].
join( ));
std::cout << "Spawned and joined " << NTHREADS << " loadThreads in "
<< time << " ms (" << (NTHREADS/time) << " threads/ms)"
<< std::endl;
for( size_t i=0; i<NTHREADS; ++i )
InitThread initThreads[NTHREADS];
for( size_t i=0; i<NTHREADS; ++i )
{
TEST( initThreads[i].
start( ));
TEST( initThreads[i].initLeft == true );
}
#ifdef _MSC_VER // resolution of Sleep is not high enough...
#else
#endif
for( size_t i=0; i<NTHREADS; ++i )
TEST( initThreads[i].
join( ));
FailThread failThread;
TEST( !failThread.start( ));
TEST( !failThread.isRunning( ));
TEST( failThread.isStopped( ));
TEST( !failThread.join( ));
return EXIT_SUCCESS;
}
Definition at line 41 of file thread.h.