相关疑难解决方法(0)

当g ++静态链接pthread时,导致分段错误,为什么?

#include <iostream>
#include <map>
#include <thread>

#define SIZE 1024
#define AMOUNT 100000
#define THREADS 4

class A
{
private:
    char a[SIZE];
};

void test()
{
    std::cout << "test start\n";
    std::map<int, A*> container;
    for(int i=0; i<AMOUNT; i++)
    {
        A* a = new A();
        std::pair<int, A*>p = std::make_pair(i, a);
        container.insert(p);
    }

    std::cout << "test release\n";
    for(int i=0; i<AMOUNT; i++)
    {
        auto iter = container.find(i);
        delete iter->second;
        container.erase(iter);
    }
    std::cout << "test end\n";
}

int main()
{
    std::thread ts[THREADS];
    for(int i=0; i<THREADS; i++) …
Run Code Online (Sandbox Code Playgroud)

c++ gcc boost pthreads c++11

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

标签 统计

boost ×1

c++ ×1

c++11 ×1

gcc ×1

pthreads ×1