|
LUNCHBOX_API | Thread () |
| Construct a new thread. More...
|
|
LUNCHBOX_API | Thread (const Thread &from) |
| Copy constructor. More...
|
|
virtual LUNCHBOX_API | ~Thread () |
| Destruct the thread. More...
|
|
virtual LUNCHBOX_API bool | start () |
| Start the thread. More...
|
|
virtual bool | init () |
| The init function for the child thread. More...
|
|
virtual void | run ()=0 |
| The entry function for the child thread. More...
|
|
virtual LUNCHBOX_API void | exit () |
| Exit the child thread immediately. More...
|
|
LUNCHBOX_API void | cancel () |
| Cancel (stop) the child thread. More...
|
|
LUNCHBOX_API bool | join () |
| Wait for the exit of the child thread. More...
|
|
LUNCHBOX_API bool | isStopped () const |
| Return if the thread is stopped. More...
|
|
LUNCHBOX_API bool | isRunning () const |
| Return if the thread is running. More...
|
|
LUNCHBOX_API bool | isCurrent () const |
|
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.