An example of the thread queue class. This may be relevant to producer- consumer scenarios and realtime applications where queued messages are stored on a re-usable object pool.
#ifndef DEBUG
#define DEBUG
#endif
#include <stdio.h>
static unsigned reused = 0;
{
public:
unsigned count;
myobject()
{count = ++reused;};
};
extern "C" int main()
{
unsigned i;
myobject *x;
for(i = 0; i < 10; ++i) {
x = myobjects.create();
mycache.post(x);
}
assert(x->count == 10);
for(i = 0; i < 3; ++i) {
x = mycache.lifo();
assert(x != NULL);
}
assert(x->count == 8);
init<myobject>(x);
assert(x->count == 11);
for(i = 0; i < 3; ++i) {
x = mycache.lifo();
assert(x != NULL);
myobjects.release(x);
}
x = init<myobject>(NULL);
assert(x == NULL);
assert(reused == 11);
return 0;
}