Skip to content
Snippets Groups Projects
Commit 146690d1 authored by Gleb Natapov's avatar Gleb Natapov Committed by Pekka Enberg
Browse files

tests: fix test_malloc to use condvar for synchronisation.


It uses low level thread::wait_until() now which calls caller supplied
predicate with preemption disabled. If caller supplied code access not yet
mapped memory it will trigger an assertion on a page fault path.

Reviewed-by: default avatarGlauber Costa <glommer@cloudius-systems.com>
Signed-off-by: default avatarGleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 75b7a789
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
#include <osv/mutex.h>
#include <osv/sched.hh>
#include <osv/debug.hh>
#include <osv/condvar.h>
#include <random>
#include "tst-hub.hh"
......@@ -28,7 +29,7 @@ public:
bool die;
bool alloc_finished;
bool free_finished;
sched::thread* main;
condvar cond;
};
void alloc_thread(test_locks &t)
......@@ -54,8 +55,10 @@ public:
}
//debug(fmt("alloc thread finished, allocated %d obj") % i);
t.lock.lock();
t.alloc_finished = true;
t.main->wake();
t.cond.wake_one();
t.lock.unlock();
}
void free_thread(test_locks &t)
......@@ -75,15 +78,16 @@ public:
sched::thread::current()->yield();
}
//debug("free thread done");
t.lock.lock();
t.free_finished = true;
t.main->wake();
t.cond.wake_one();
t.lock.unlock();
}
void run()
{
test_locks t;
t.die = t.free_finished = t.alloc_finished = false;
t.main = sched::thread::current();
sched::thread* t1 = new sched::thread([&] { alloc_thread(t); });
sched::thread* t2 = new sched::thread([&] { free_thread(t); });
t1->start();
......@@ -95,7 +99,9 @@ public:
nanosleep(&ts, nullptr);
t.die = true;
t.main->wait_until([&] {return (t.alloc_finished && t.free_finished);});
t.lock.lock();
t.cond.wait_until(t.lock, [&] {return (t.alloc_finished && t.free_finished);});
t.lock.unlock();
t1->join();
t2->join();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment