Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8438475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:43:42+00:00 2026-06-10T07:43:42+00:00

I am new to using threads, and I thought a good excercise would be

  • 0

I am new to using threads, and I thought a good excercise would be to write a queue that works with threads. However, something is wrong, I suspect that the consumer threads try to access the same data or something. I use mutexes but I probably has misunderstood something…

I get this error (about every third run):

*** glibc detected *** ./t_queue_test: double free or corruption (fasttop): 0x0000000002114610 ***

The code is rather long so I’ve posted it on pastebin, but if thats incorrect, I can paste it here.

t_queue.h -> http://pastebin.com/2KYmujeE

t_queue.c -> http://pastebin.com/1wZPMwDB

t_queue_test.c -> http://pastebin.com/QKCTQWaf

I thinks the error occures in function ‘get_q’, and I’ve marked it in the code.

Thanks for any pointers or suggestions. I’ve digged around stackoverflow for similar questions, and I will dig some more! Valgrind doesn’t show anything yet either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:43:43+00:00Added an answer on June 10, 2026 at 7:43 am

    Just a note for later in case pastebin goes away; the faulty code is this;

    if(q->rear != NULL && q->front != NULL)
    {
        node_n = q->front;
        *d = node_n->data;
        q->front = node_n->next;
        free(node_n);           
    }
    

    It cleans up the front quite ok, however if the last element is removed, rear also needs to be updated to reflect the queue being empty. For example, this will do it;

    if(q->rear != NULL && q->front != NULL)
    {
        node_n = q->front;
        *d = node_n->data;
        q->front = node_n->next;
        if(q->front == NULL) 
          q->rear = NULL;
        free(node_n);
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to threads. I'm using a 3rd party library that uses threads which
I'm using the new iOS 5 core data concurrency options. I have two threads:
For Create And Start New Threads In C# We Act Like Below : using
I am programming some 'openvpn-like' thing and thought it would be a good candidate
I think I’m using threads wrong so I wanted to ask if this was
I want to start a new thread using a C function, not an objective-C
What are the differences in using boost:thread, Posix Thread library and the new C++11
I'm trying to create a new System.Threading.Thread object using Jscript, but I can't get
I am using System.Timers in my program. As we know each interval new thread
I'm new using the excellent stuff of css twitter bootstrap and having a problem,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.