A simple example of threading and join operation.
A simple example of threading and join operation.
#ifndef DEBUG
#define DEBUG
#endif
#include <stdio.h>
static unsigned count = 0;
class testLocal : public Thread::Local
{
private:
virtual void release(void *mem) __FINAL {
::free(mem);
}
virtual void *allocate() __FINAL {
return ::malloc(100);
}
};
static testLocal local;
{
public:
void run(void) {
assert(local.get() == nullptr);
assert(*local != nullptr);
++count;
::sleep(2);
};
};
extern "C" int main()
{
time_t now, later;
testThread *thr;
void *mem;
assert(local.get() == nullptr);
mem = *local;
assert(mem != nullptr);
assert(mem == *local);
time(&now);
thr = new testThread();
thr->start();
Thread::sleep(10);
delete thr;
assert(count == 1);
time(&later);
assert(later >= now + 1);
time(&now);
time(&later);
assert(later >= now + 1);
return 0;
}
Top level include file for the GNU uCommon C++ core library.
Common namespace for all ucommon objects.
Event notification to manage scheduled realtime threads.
bool wait(timeout_t timeout)
Wait to be signalled or until timer expires.
A child thread object that may be joined by parent.