我一直在阅读有关多线程,C++,正确同步和锁定的不同内容,以防止竞争条件.但是,有一个问题没有得到解答: 如果我在线程A中创建一个对象,是否需要互斥锁,但之后在线程B中只使用它?
换句话说,我知道我不需要互斥锁来防止竞争条件 - 我是否需要互斥锁作为内存屏障(或其他潜在问题)?
一个非常基本的例子,可视化我的意思
struct Object {
void do_stuff();
};
Object o;
std::thread worker_thread([&o](){
while (alive)
o.do_stuff();
}).join();
// `o` is never used outside worker_thread
Run Code Online (Sandbox Code Playgroud)
如果你还可以推荐我的文章/书籍,我可以在这里阅读更多关于这个主题和/或正确的关键词来搜索这些场景,我会很高兴.
我目前正在尝试将所有应用程序的依赖项编译为静态库。我的动机:
However, as I initially dreaded I had to go down the rabbit hole quite fast. I am currently stuck with OpenCV and I'm sure there is more to come. However, my main questions are:
我想要绘制的是以下内容:
但是在箭头的中心加上一个加号而不是一个减号.
我想从白色底座形状中减去"减号".奇怪的是,对于减号可以正常工作,但是如果我绘制一个加号而不是它不再减去它,而是将它添加到底层路径.
减去减号的我的代码看起来像这样
Path base = new Path();
[... draw the arrow ]
Path subtract = new Path();
subtract.moveTo(-xBarWidth/2, -xBarHeight/2); // center the path
subtract.rLineTo(xBarWidth, 0);
subtract.rLineTo(0, xBarHeight);
subtract.rLineTo(-xBarWidth, 0);
subtract.rLineTo(0, -xBarHeight);
base.add(subtract);
[in paint() function: canvas.draw(base, paint)]
Run Code Online (Sandbox Code Playgroud)
加号的代码:
int halfBarWidth = xBarWidth/2;
subtract.moveTo(-halfBarWidth, -xBarHeight/2);
subtract.rLineTo(halfBarWidth, 0);
subtract.rLineTo(0, halfBarWidth);
subtract.rLineTo(xBarHeight, 0);
subtract.rLineTo(0, -halfBarWidth);
subtract.rLineTo(halfBarWidth, 0);
subtract.rLineTo(0, -xBarHeight);
subtract.rLineTo(-halfBarWidth, 0);
subtract.rLineTo(0, -halfBarWidth);
subtract.rLineTo(-xBarHeight, 0);
subtract.rLineTo(0, halfBarWidth);
subtract.rLineTo(-halfBarWidth, 0);
subtract.rLineTo(0, xBarHeight);
Run Code Online (Sandbox Code Playgroud)
但是,现在它在箭头顶部绘制了白色加号.我试过subtract.setFillType(FillType.INVERSE_EVEN_ODD)但它没有改变任何东西.
不幸的是我在api找不到任何帮助.
目前我们使用 ProtocolBuffers 在 python 和 C++ 之间交换数据。但是,我们遇到了协议缓冲区的最大文件大小限制,并正在考虑将所有内容切换到 Cap'n Proto。但是,由于它与协议缓冲区有些相关,我想知道Cap'n Proto 是否对最大文件大小也有限制?