小编Rha*_*hin的帖子

Can deadlock occur in this code snippet and why?

Is deadlock possible in the following code snippet:

void f()
{
    {
        std::lock_guard <std::mutex> inner (lock1);
        // do something and conditionally return
    }
    std::lock_guard <std::mutex> outer (lock2);
    // do something
}
Run Code Online (Sandbox Code Playgroud)

IOW, if multiple threads call this function, can a deadlock occur?

I am not too sure so any help would be highly appreciated.

c++ c++11

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

如何将类类型作为参数传递给新操作的函数模板?

我有一段 C++ 代码:

#include <iostream>
#include <string>
#include <map>

static counter = 0;

class Probe
{
private:
    int supply_;
    Probe(const Probe&);

public:
    Probe()
    {
        supply_ = 10000;
    }

    int get_supply()
    {
        return supply_;
    }

};

/********************************************************************************
template<class T> T Create(int counter, T& produced)
{
    produced[counter] = new ; // ??????????????????????????????????????
    return produced;
}
************************************************************************************/

std::map<int, Probe*> CreatInitWorkers(int counter, std::map<int, Probe*> &init_workers) 
{
    init_workers[counter] = new Probe(); 
    return init_workers;
}


int main()
{ 
    std::map<int, Probe*> workers;
    for (int i = 0; …
Run Code Online (Sandbox Code Playgroud)

c++ class new-operator function-templates

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

比较“A”、“C”、“G”、“T”字符的最快方法

我希望提高我的生物信息学算法的速度,这需要比较“A”、“C”、“G”、“T”之一的字符(例如计算“A”==“C”)

由于字符的大小为 8 位,因此在最坏的情况下需要对二进制数进行 8 次比较。我的猜测是,通过将 'A'、'C'、'G'、'T' 表示为一对二进制数(例如,将 'A' 表示为 make_pair(false,false)),我想我可以提高速度3~4 次,因为它现在最多只需要 2 次二进制比较。

我尝试使用一对布尔值,但速度实际上下降了大约 30%。

表示四个字符和计算相等性的最快方法是什么?内存使用对我来说并不是什么大问题。

供您参考,我使用的是 C++11 编译器。先感谢您。

c++ binary performance bioinformatics char

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