我想我有一个非常糟糕的概念问题.为什么我简单地用valgrind获得了很多竞争条件错误.首先我认为这可能是一个错误,我在论坛中看到linux的更新滚动版本将解决这个问题...所以现在我已经打开了tubleweed,100%更新.以下代码muss有一些非常错误:
#include <iostream>
#include <thread>
using namespace std;
class FOO
{
public:
void do_something ()
{
cout<<"cout somethin\n";
}
};
int main ()
{
FOO foo;
std::thread t (&FOO::do_something,&foo);
t.join();
}
Run Code Online (Sandbox Code Playgroud)
当我做的时候
valgrind --tool=drd ./oncordia
Run Code Online (Sandbox Code Playgroud)
我必须尝试5次或更多,我得到以下错误:
==6218== drd, a thread error detector
==6218== Copyright (C) 2006-2010, and GNU GPL'd, by Bart Van Assche.
==6218== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==6218== Command: ./oncordia
==6218==
cout somethin
==6218== Conflicting store by thread 1 at 0x05b5d050 size 8 …Run Code Online (Sandbox Code Playgroud) 这是一个算法问题.为了简单起见,我说我有两个双打,A和B.我想构建一个函数,它会给我差异,直到A的下一个倍数或B的下一个倍数,如果这有意义的话.
例如,假设A是3而B是5.
考虑倍数:(3,6,9,12,15)和(5,10,15).
我希望函数输出:(3,2,1,3,1,2,3),因为它需要3个单位才能达到3,然后再多达2个到达5,然后是1到6,然后是3到9等...
我希望这是有道理的.理想情况下,它是一个Python-esque生成器(虽然我在Arduino~C++中编写它).我需要快速 - 非常快.
真的很感激任何帮助.我的伪代码在下面,但它不是那么好.
a = 3
b = 5
current = 0
distToA = a
distToB = b
for i in xrange(100):
if distToA > distToB: #B comes first
print "Adding {0}".format(distToB)
current += distToB
distToA -= distToBb
distToB = b
elif distToB > distToA: #A comes first
print "Adding {0}".format(distToA)
current += distToA
distToB -= distToA
distToA = a
else: #Equal
print "Adding {0}".format(distToA)
current += distToA #Arbitrarily, could be distToB
distToA = a …Run Code Online (Sandbox Code Playgroud)