小编use*_*255的帖子

在线程A中创建对象,在线程B中使用.需要Mutex吗?

我一直在阅读有关多线程,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)

如果你还可以推荐我的文章/书籍,我可以在这里阅读更多关于这个主题和/或正确的关键词来搜索这些场景,我会很高兴.

c++ multithreading mutex

14
推荐指数
1
解决办法
837
查看次数

完全静态构建具有所有依赖项(libgcc 等)的应用程序?

我目前正在尝试将所有应用程序的依赖项编译为静态库。我的动机:

  1. 不依赖任何操作系统提供的库以获得完美可重现的代码库
  2. 避免在其他系统上部署时由动态链接引起的问题
  3. 链接不同版本的库时避免运行时冲突
  4. 能够为其他操作系统交叉编译

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:

  1. Is it possible to build an entirely statically build app (e.g. libc, ligcc, etc. ?)
  2. Is it possible to link all libraries statically but link major components (libgcc, etc.) dynamically?
  3. If not, is it possible to link against statically …

c++ linker dynamic-linking static-linking libgcc

6
推荐指数
1
解决办法
1110
查看次数

使用android.graphics.Path从另一个形状中删除一个形状

我想要绘制的是以下内容: 截图 但是在箭头的中心加上一个加号而不是一个减号.

我想从白色底座形状中减去"减号".奇怪的是,对于减号可以正常工作,但是如果我绘制一个加号而不是它不再减去它,而是将它添加到底层路径.

减去减号的我的代码看起来像这样

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找不到任何帮助.

android drawing 2d

5
推荐指数
1
解决办法
2077
查看次数

CapnProto 最大文件大小

目前我们使用 ProtocolBuffers 在 python 和 C++ 之间交换数据。但是,我们遇到了协议缓冲区的最大文件大小限制,并正在考虑将所有内容切换到 Cap'n Proto。但是,由于它与协议缓冲区有些相关,我想知道Cap'n Proto 是否对最大文件大小也有限制?

protocol-buffers capnproto

2
推荐指数
1
解决办法
681
查看次数