|
From: Detlef V. <dv...@vo...> - 2013-01-10 23:44:58
|
Hi,
I'm testing a small program that in a tight (busy) loop checks that another
thread has reached some specific state.
With valgrind, this runs forever on some machines, and returns pretty soon on
other (much slower) machines.
Is this a known problem and is there a workaround?
I'm running Valgrind-3.7.0.
Here's the program, and everything works fine with valgrind if I add a sleep in
the loop (HERE).
Detlef
#include <thread>
#include <condition_variable>
#include <mutex>
using std::mutex;
using std::unique_lock;
bool started = false;
bool running = false;
mutex startedMtx;
mutex runningMtx;
std::condition_variable runningCond;
void foo()
{
running = true;
{
unique_lock<mutex> lock(startedMtx);
started = true;
}
unique_lock<mutex> lock(runningMtx);
while (running) {
runningCond.wait(lock);
}
}
int main()
{
std::thread t(&foo);
bool goOn = false;
while (!goOn) {
unique_lock<mutex> lock(startedMtx);
goOn = started;
// HERE
}
{
unique_lock<mutex> lock(runningMtx);
running = false;
runningCond.notify_one();
}
t.join();
return 0;
}
|
|
From: Philippe W. <phi...@sk...> - 2013-01-11 05:50:28
|
On Thu, 2013-01-10 at 23:38 +0000, Detlef Vollmann wrote: > Hi, > > I'm testing a small program that in a tight (busy) loop checks that another > thread has reached some specific state. > With valgrind, this runs forever on some machines, and returns pretty soon on > other (much slower) machines. > > Is this a known problem and is there a workaround? > I'm running Valgrind-3.7.0. > > Here's the program, and everything works fine with valgrind if I add a sleep in > the loop (HERE). I guess you might have encountered the bug https://bugs.kde.org/show_bug.cgi?id=270006 If that is the case, you should upgrade to 3.8.1 and use the new option --fair-sched=yes Philippe |
|
From: Julian S. <js...@ac...> - 2013-01-11 10:25:33
|
On 01/11/2013 12:38 AM, Detlef Vollmann wrote: > Hi, > > I'm testing a small program that in a tight (busy) loop checks that another > thread has reached some specific state. > With valgrind, this runs forever on some machines, and returns pretty soon on > other (much slower) machines. > > Is this a known problem and is there a workaround? Yes and yes. Upgrade to 3.8.1 and use --fair-sched=yes. J |