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 8798129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:00:40+00:00 2026-06-14T00:00:40+00:00

I am using POSIX threads, and at the end of my program, I am

  • 0

I am using POSIX threads, and at the end of my program, I am waiting to join each of the threads. After some time of running perfectly well, my code started returning a weird bug when I was waiting for the threads.

pthreads threads[C+P];

for(i = 0; i < (C+P); i++)
{
    printf("%d\n", i);  
    pthread_join(threads[i]);
}

If I remove the printf statement, or replace it with any other printf statement, a delay, or any other operation on i, I still get a segfault.

How would I start debugging this?

  • 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-14T00:00:41+00:00Added an answer on June 14, 2026 at 12:00 am

    Inserting printf() call affects memory layout (and thus it can, by pure accident, mask some memory corruption), as well as execution timing (you use threads, so timing is also relevant).

    But instead of any sort of guesswork, you should do some regular debugging:

    • run you executable under gdb, this way you should be able to see what exact operation is causing a crash, where is it called from, etc.

    • run it under valgrind – this tool detects a lot of common errors, like accessing free’d memory block, using uninitialized variables, exceeding array/buffer boundaries, etc. It’s not uncommon to immediately get exact position of the error with valgrind, I highly recommend it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some code using posix threads but I'm stuck from the
I am trying to debug (using gdb) a multi-threaded program, which uses POSIX threads.
I've got a multithreaded server (using POSIX threads), with one thread for each persistent
I'm trying to implement a blocking queue using POSIX threads. Important code segments are
I have a question about some code I'm testing to start understanding posix threads.
I'm using Posix Message Queues on Linux. Basically, I have multiple threads that receive
Specifically, I'm using the Linux command: $ find . -regextype posix-extended -regex '<some regex>'
I've written some library code (in C) to facilitate creating and querying threads independent
I have some problem using the clock_gettime() function. #include <iostream> #include <time.h> timespec timer_start;
A slow multiple precision implementation of a mandelbrot generator. Threaded, using POSIX threads. Gtk

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.