46 lines
798 B
C++
46 lines
798 B
C++
#include <rt/rwlock.hpp>
|
|
#include <rt/task.hpp>
|
|
#include <rt/trap.hpp>
|
|
|
|
#include <rt/assert.h>
|
|
|
|
static rt::rwlock lock;
|
|
static unsigned x = 0;
|
|
static unsigned y = 0;
|
|
|
|
static void reader(void)
|
|
{
|
|
rt::task::drop_privilege();
|
|
for (;;)
|
|
{
|
|
rt::rdlock_guard rdlock(lock);
|
|
rt_assert(x == y, "x and y don't match");
|
|
}
|
|
}
|
|
|
|
static void writer(void)
|
|
{
|
|
rt::task::drop_privilege();
|
|
for (;;)
|
|
{
|
|
{
|
|
rt::wrlock_guard wrlock(lock);
|
|
++x;
|
|
++y;
|
|
}
|
|
rt::task::sleep(1);
|
|
}
|
|
}
|
|
|
|
static void timeout(void)
|
|
{
|
|
rt::task::drop_privilege();
|
|
rt::task::sleep(1000);
|
|
rt::trap();
|
|
}
|
|
|
|
RT_TASK(reader, RT_STACK_MIN, 1);
|
|
RT_TASK(reader, RT_STACK_MIN, 1);
|
|
RT_TASK(writer, RT_STACK_MIN, 1);
|
|
RT_TASK(timeout, RT_STACK_MIN, 2);
|