小编use*_*183的帖子

C++ ThreadPool没有并行运行

我试图实现一个ThreadPool,但不幸的是我遇到了一些问题.

这就是我已经拥有的.

//includes ...

void call()
{
    std::cout << "Hi i'm thread no " << std::this_thread::get_id() << std::endl;
    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout << "ready " << std::this_thread::get_id() << std::endl;
};

//Implementation is not shown here to reduce code
class WorkQueue {
    public:
        bool push(std::function<void()> const& value);
        void pop();
        bool empty();
};

std::condition_variable g_queuecheck;
std::mutex              g_lockqueue;
std::atomic<bool>       g_notified;

class ThreadPool
{
    public:
        ThreadPool(int iNoThread) :
            m_noThread(iNoThread)
        {
            g_notified.store(false);
            m_threads.resize(iNoThread);
            bIsReady.store(false);
            for (int i = 0; i < iNoThread; ++i)
                m_threads[i] = std::thread(&ThreadPool::run, this); …
Run Code Online (Sandbox Code Playgroud)

c++ concurrency threadpool

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

Canny算法中的非最大抑制:使用SSE进行优化

我有"荣幸"来改善其他人的以下代码的运行时间.(这是来自canny - 算法的非最大限制).我的第一个想法是使用SSE内在代码,我在这方面很新,所以我的问题是.

有没有机会这样做?如果是这样,有人可以给我一些提示吗?

void vNonMaximumSupression(
          float* fpDst, 
          float const*const fpMagnitude, 
          unsigned char  const*const ucpGradient,                                                                           ///< [in] 0 -> 0°, 1 -> 45°, 2 -> 90°, 3 -> 135°
int iXCount, 
int iXOffset, 
int iYCount, 
int ignoreX, 
int ignoreY)
{
    memset(fpDst, 0, sizeof(fpDst[0]) * iXCount * iXOffset);

    for (int y = ignoreY; y < iYCount - ignoreY; ++y)
    {
        for (int x = ignoreX; x < iXCount - ignoreX; ++x)
        {
            int idx = iXOffset * y + x;
            unsigned …
Run Code Online (Sandbox Code Playgroud)

c++ sse computer-vision edge-detection canny-operator

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

c ++:表查找是否可以为小查找表进行矢量化

我想用SIMD内在函数来矢量化以下代码片段这可能吗?

unsigned char chain[3][3] = { 
            3,  2, 1,    //  y    --> x
            4, -1, 0,    //  | 
            5,  6, 7     //  |
            };           //  v    

std::vector<int> x;
std::vector<int> y;    
//initialize x, y

std::vector<int> chain_code(x.size());

for(std::size_t i = 0; i < x.size(); ++i
     chain_code[i] = chain[x[i]][y[i]];    
Run Code Online (Sandbox Code Playgroud)

编辑:

支持:SSE - SSE4.2和AVX

Architectur:Sandy Bridge i5 2500

c++ x86 sse simd avx

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

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

是否重新分配向量会导致父向量的重新分配?

观看以下代码片段.在所有平台上的所有情况下,输出总是错误的吗?

  std::vector<std::vector<int>> array(5);
  array[0].resize(1);
  std::vector<int>* arr_start = array.data();
  int* p_start = array[0].data();

  while( p_start == array[0].data())
  {
     array[0].push_back(0);
  }

  std::cout << "Does a reallocation in a vector leads to a reallocation in the parent vector? " 
            << array.data() != arr_start;
Run Code Online (Sandbox Code Playgroud)

c++ vector

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

静态变量的数量是否受限于C++

我正在与一个声称支持C++的平台上的开发人员交谈,但是他们同时说,在程序出口处清除的静态变量的数量被绑定到一个神奇的数字(我认为他们说32在他们的平台上),他们说这符合C++标准.

它是否正确?

c++ language-lawyer

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

当绑定对象到期时,std :: bind创建的仿函数的行为是否定义良好?

是否定义了以下代码的行为?f()通话如何表现?

#include <functional>
#include <iostream>

struct A
{
  void shout()
  {
      std::cout <<"shout";
  }
};


int main()
{
    std::function<void()> f;
    {
        A a;
        f = std::bind(&A::shout, &a);
    }

    f();  // what happens here?
}
Run Code Online (Sandbox Code Playgroud)

c++ language-lawyer stdbind

0
推荐指数
1
解决办法
50
查看次数