/usr/include/wibble/sys/thread.test.h is in libwibble-dev 0.1.28-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | /* -*- C++ -*- (c) 2007 Petr Rockai <me@mornfall.net>
(c) 2007 Enrico Zini <enrico@enricozini.org> */
#include <wibble/sys/mutex.h>
#include <wibble/sys/thread.h>
#include <wibble/test.h>
using namespace std;
using namespace wibble::sys;
struct TestThread {
// Test threads that just assigns a value to an int and exists
class Thread1 : public Thread
{
protected:
int& res;
int val;
void* main()
{
res = val;
return (void*)val;
}
public:
Thread1(int& res, int val) : res(res), val(val) {}
};
// Thread that continuously increments an int value
class Thread2 : public Thread
{
protected:
int& res;
Mutex& mutex;
bool done;
void* main()
{
while (!done)
{
MutexLock lock(mutex);
++res;
}
return 0;
}
public:
Thread2(int& res, Mutex& mutex) :
res(res), mutex(mutex), done(false) {}
void quit() { done = true; }
};
// Test that threads are executed
Test execution() {
int val = 0;
Thread1 assigner(val, 42);
assigner.start();
assert_eq(assigner.join(), (void*)42);
assert_eq(val, 42);
}
// Use mutexes to access shared memory
Test sharedMemory() {
int val = 0;
Mutex mutex;
Thread2 incrementer(val, mutex);
incrementer.start();
bool done = false;
while (!done)
{
MutexLock lock(mutex);
if (val > 100)
done = true;
}
incrementer.quit();
assert_eq(incrementer.join(), (void*)0);
}
};
// vim:set ts=4 sw=4:
|