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

  • Home
  • SEARCH
  • 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 7525045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:13:47+00:00 2026-05-30T03:13:47+00:00

I am writing a program using threads in c++ in linux. Currently, I am

  • 0

I am writing a program using threads in c++ in linux.

Currently, I am just keeping an array of threads, and every time one second has elapsed, I check to see which have finished, and restart them. Is this bad? I need to keep this program running for a long time. As it is now, I am getting a code 11 after so many loops of restarting threads (the 100th loop in the last trial). I figured that reusing threads and making sure I only have a small number of them running at any one time, that I would not hit the limit. The array I am using only has a size of 8 (of course, I am not starting 8 each time, just those that have stopped).

Any ideas?

My code is below:

if ( loop_times == 0 || pthread_kill(threads[t],0) != 0 ) 
{ 
    rc = pthread_create(&threads[t], NULL, thread_stall, (void *)NULL); 
    if (rc){ 
        printf("ERROR; return code from pthread_create() is %d\n", rc); 
        exit(-1); 
    } 
thread_count++; 
} 

The loop_times variable is just so that I can get into the loop and start the threads the first time. Otherwise, I get a SEGFAULT because the threads haven’t been started before.

Also, I have been wanting to see the value of PTHREAD_THREADS_MAX, but I can’t print it (even when including limits.h)

  • 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-05-30T03:13:49+00:00Added an answer on May 30, 2026 at 3:13 am

    As it turns out, my problem was that I needed to pthread_join my thread before I restarted it each time. After this, I stopped getting a code 11 and stopped having “still reachable” memory when running it through Valgrind.

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

Sidebar

Related Questions

I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
I am writing a multi-threaded program using OpenMP in C++. At one point my
I'm writing a prime sieve program using eratosthenes' for class. I have 8 threads
I am writing a program which has 8 threads. I am implementing a barrier
I am writing code for a real-time program running in an embedded Linux system.
I'm writing a program on Linux in C, and I'd like to wait (using
I'm writing a ruby program that will be using threads to do some work.
I am writing a server program in C wherein every time a client connects,
I am writing a program using Delphi 2006 and storing data in XML files
I'm writing a program using C++ and the MySQL C API (version 5.1.31 ubuntu2).

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.