队列+ libsoup。记忆违规 [英] Queue + libsoup. Memory vioalation

查看:54
本文介绍了队列+ libsoup。记忆违规的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序在c ++中使用libsoup和queue编写了问题。



I have problem with my program writed in c++, using libsoup and queue.

void operator()()
{
    ELEMENT e;
    while(1)
    {
        if(!fq->empty())
        {

            mutex.lock();
            e = fq->front();


            run(server, &e);


            fq->pop();

            mutex.unlock();
        }





在我添加ExecuteLoop以建立队列之前,它工作正常。当我运行它并开始向服务器发出请求时,我看到内存通过错误。它不时给我更多信息:





It works good before I add ExecuteLoop to make an queue. When I run it and start to make requests to the server I see memory vialation error. From time to time it gives me more information:

*** glibc detected *** ./fifo: double free or corruption (!prev): 

0x0a23e758 ***
======= Backtrace: =========
(...)





我不知道我在哪里弄错了。你能帮助我吗?



I have no idea where I make a mistake. Can you help me?

推荐答案

我不是要求了解这一切是怎么做的,而是考虑以下几点:



I don''t claim to understand what all this is doing but consider these lines:

if(!fq->empty())
  {

      queue_mutex.lock();
      e = fq->front();





如果在测试条件时队列不为空但在锁定被置位之前它是空的,会发生什么情况?

这种情况​​可能会发生,也就是说它会发生。也许您需要在检查前移动锁或重做锁内的检查?



What happens if the the queue is not empty when the condition is tested but it is empty before the lock is asserted?
This can happen which is the same as to say it will happen. Perhaps you need to move the lock before the check or redo the check inside the lock?


这篇关于队列+ libsoup。记忆违规的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆