Click here to Skip to main content
11,484,941 members (77,069 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Linux
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();
            }

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?
Posted 6-Apr-13 23:29pm
Edited 21-May-13 5:57am
v7

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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?
  Permalink  
Comments
Matthew Faithfull at 8-Apr-13 7:59am
   
Not sure in that case. I would start by confirming that the error occurs during the fq->pop(); call. Perhaps even comment that out to confirm it then doesn't crash although of course the fifo will fill up and the same message will get processed repeatedly. Anyway it seems like its claiming there's a pop from an empty queue which is wierd. Sorry I can't really help you futher.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 330
1 Maciej Los 280
2 Raje_ 155
3 Mehdi Gholam 150
4 OriginalGriff 133
0 Sergey Alexandrovich Kryukov 8,494
1 OriginalGriff 7,948
2 Sascha Lefèvre 3,199
3 Maciej Los 2,681
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 21 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100