A simple example of threading and join operation.
#ifndef DEBUG
#define DEBUG
#endif
#include <stdio.h>
using namespace UCOMMON_NAMESPACE;
static unsigned count = 0;
class testThread : public JoinableThread
{
public:
testThread() : JoinableThread() {};
void run(void) {
++count;
::sleep(2);
};
};
extern "C" int main()
{
time_t now, later;
testThread *thr;
time(&now);
thr = new testThread();
Thread::sleep(10);
delete thr;
assert(count == 1);
time(&later);
assert(later >= now + 1);
time(&now);
TimedEvent evt;
evt.wait(2000);
time(&later);
assert(later >= now + 1);
return 0;
}