开发者

Segmentation fault from pop_front() in C++

开发者 https://www.devze.com 2023-02-17 17:38 出处:网络
My problem is that I am getting a segmentation fault that occurs after I call \"processList.pop_front()\".If I comment out \"processList.pop_front()\", a segmentation then occurs during the second ite

My problem is that I am getting a segmentation fault that occurs after I call "processList.pop_front()". If I comment out "processList.pop_front()", a segmentation then occurs during the second iteration of the outermost for loop, after a tt.pop_front() call, after that inner for loop has gone through almost 5000 iterations. I can't see what the problem is. Any thoughts?

loopLimit = processList.size();

for(int i = 0; i < loopLimit; i++)
{
    tempProcess = processList.front();
    tt = tempProcess.memAccesses;
    cout << "process number " << i << "\n";

    while(!tt.empty())
    {
        t = tt.front();
        tt.pop_fron开发者_高级运维t();
        cout << "from processlist: " << t.instrType << "  " << t.instrAddr << "\n";
    }

    if(!processList.empty())
    {
        cout << "size is now: " << processList.size() << "\n";
        processList.pop_front();
    }

}


I have a similar problem and I solved it by adding an invalid value to the deque:

loopLimit = processList.size();

for(int i = 0; i < loopLimit; i++)
{
    tempProcess = processList.front();
    tt = tempProcess.memAccesses;
    cout << "process number " << i << "\n";

    tt.push_back(-1);  //I guess you don't have a -1 type, so you wont have colisions
    while( tt.front()!=-1)
    {
        t = tt.front();
        tt.pop_front();
        cout << "from processlist: " << t.instrType << "  " << t.instrAddr << "\n";
    }

    if(!processList.empty())


    {
        cout << "size is now: " << processList.size() << "\n";
        processList.pop_front();
    }

}

Probably you will have to adapt it a bit. Is not a very nice solution, but it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消