小编mxd*_*ois的帖子

C++智能指针是否无锁?

以下操作是否可以锁定std::unique_ptr和/或std::shared_ptr

  1. 解除引用,即read(*myPtr)myPtr->getSomething()
  2. 删除引用,即使用std::move(myUniquePtr)或当std::shared_ptr超出范围时.

就我而言,我不会同时从多个线程访问这些指针.我只是好奇我是否可以在高优先级,无锁线程上专门使用它们.由指针管理的对象在高优先级回调之前由主线程分配,并且在回调停止之前不会被释放.

谢谢!

c++ multithreading smart-pointers lock-free c++11

5
推荐指数
2
解决办法
1138
查看次数

在Android NDK上使用Google Test测试'typeinfo for testing :: Test'的未定义引用

我正在尝试使用Android NDK进行Google测试.在这里NDK README示例之后,我已经设置了我的Android.mk和单个测试,如下所示,但我收到此错误:

./obj/local/armeabi/objs-debug/ndkfoo_unittest/FilteredPriorityQueue_test.o:FilteredPriorityQueue_test.cpp:function typeinfo for mashbot::FilteredPriorityQueueTest_ShouldRetrieveTop_Test: error: undefined reference to 'typeinfo for testing::Test'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi/ndkfoo_unittest] Error 1    
Run Code Online (Sandbox Code Playgroud)

这是我目前所知道的:

  • ::testing::Test是由TEST()宏自动子类化的Google Test类.
  • undefined reference to 'typeinfo for 当链接器找不到虚拟方法的定义时,通常会发生错误.
  • 可能是因为使用不同的标志编译谷歌测试,但不应该是这种情况,因为我使用的是静态谷歌测试库,两个模块之间的标志是相同的.

我错过了什么?或者我在哪里可以看到下一个?谢谢!

更新:如果我从ndkfoo_unittest模块中删除SHARED_LIBRARIES,CPP_FLAGS和LDLIBS,我可以构建一个不依赖于Boost或Android原生apis的简单Google Test.

构建命令:

ndk-build SHELL=/bin/bash NDK_DEBUG=1
Run Code Online (Sandbox Code Playgroud)

FilteredPriorityQueue_test.cpp:

#include "gtest/gtest.h"

// FilteredPriorityQueue is a header-only file with no virtual methods.
#include "FilteredPriorityQueue.h"

// So is Comparator.
#include "Comparator.h"

struct MaskedObject {
    int mMask;
    MaskedObject(int mask) …
Run Code Online (Sandbox Code Playgroud)

c++ android makefile googletest android-ndk

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

确保线程没有锁定互斥锁两次?

假设我有一个运行成员方法的线程runController,如下例所示:

class SomeClass {
public:
    SomeClass() { 
         // Start controller thread
         mControllerThread = std::thread(&SomeClass::runController, this) 
    }

    ~SomeClass() {
         // Stop controller thread
         mIsControllerThreadInterrupted = true;
         // wait for thread to die.
         std::unique_lock<std:::mutex> lk(mControllerThreadAlive); 
    }

    // Both controller and external client threads might call this
    void modifyObject() {
         std::unique_lock<std::mutex> lock(mObjectMutex);
         mObject.doSomeModification();
    }
    //...
private:
    std::mutex mObjectMutex;
    Object mObject;

    std::thread mControllerThread;
    std::atomic<bool> mIsControllerInterrupted;
    std::mutex mControllerThreadAlive;

    void runController() {        
        std::unique_lock<std::mutex> aliveLock(mControllerThreadAlive);
        while(!mIsControllerInterruped) {
            // Say I need to synchronize on mObject …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading deadlock locking c++11

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

Sass @extend base/default还没有扩展伪类?

我知道我可以@extend .foo:hover,但有没有办法@extend .foobar base/default属性而不扩展伪类的定义,如:hover,:active等?

例如,我如何更改以下内容以使.foobar仅扩展.foo的默认状态?

.foo {
    & {
         color:blue;
    }
    &:hover {
         background-color: black;
    }
}

.foobar {
     @extend .foo;
     &:hover {
          //As is, I have to override. Any better way?
          background-color: transparent;
     }
}
Run Code Online (Sandbox Code Playgroud)

(如果没有办法用Sass做到这一点,有没有一种方法可以达到同样的效果?)

css sass extend css-selectors

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

Android OpenSL"pAudioSrc:数据格式2不允许" - 拒绝SL_DATAFORMAT_PCM?

我正在尝试使用bufferqueue source和outputmix sink创建一个AudioPlayer.我已经使用与ndk示例中显示的pcm格式非常相似的pcm格式配置了源,但OpenSL拒绝AudioPlayer("数据格式2").这对我没有任何意义.

这是错误(在三星Galaxy S2上):

02-27 15:43:47.315: E/libOpenSLES(12681): pAudioSrc: data format 2 not allowed
02-27 15:43:47.315: W/libOpenSLES(12681): Leaving Engine::CreateAudioPlayer (SL_RESULT_CONTENT_UNSUPPORTED)
Run Code Online (Sandbox Code Playgroud)

这是相关的代码:

SLuint32 channels = 2;
SLuint32 speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
SLuint32 sr = SL_SAMPLINGRATE_48;

//...
SLDataFormat_PCM format_pcm = {
    SL_DATAFORMAT_PCM,
    channels,
    sr,
    SL_PCMSAMPLEFORMAT_FIXED_16,
    SL_PCMSAMPLEFORMAT_FIXED_16,
    speakers,
    SL_BYTEORDER_LITTLEENDIAN
};

// Configure audio player source
SLDataLocator_AndroidBufferQueue loc_bufq =
    {SL_DATALOCATOR_ANDROIDBUFFERQUEUE, 2};
SLDataSource audioSrc = {&loc_bufq, &format_pcm};

// configure audio player sink
SLDataLocator_OutputMix loc_outmix =
    {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL}; …
Run Code Online (Sandbox Code Playgroud)

java android android-ndk opensl

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