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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:54:34+00:00 2026-06-06T19:54:34+00:00

I have a struck with an array of pthread pointers. Each thread is meant

  • 0

I have a struck with an array of pthread pointers. Each thread is meant to read a different data stream

typedef struct {
  // ...other stuff
  pthread_t *threads[MAX_STREAM_COUNT];
} stream_manager;

And when I want to start reading:

void start_reading(stream_manager *sm, int i) {
   // do some pre processing stuff
   pthread_create( (pthread*) &sm->threads[i], 
                              NULL, 
                              read_stream_cb, 
                      (void*) sm->streams[i]       );
}

When I want to stop reading:

void stop_reading(stream_manager *sm, int i) {
   iret = pthread_join(*sm->threads[i], NULL);
   if(iret != 0) {
     perror("pthread_join returned with error:: ");
     printf( "pthread_join returned with error:: %s\n", strerror(iret) )
   }
}

For now, my read_stream_cb function simply prints the name of the stream its reading from.

void* read_stream_cb(stream *strm) {
   stream *s = (stream*) strm;
   prinf("%s\n", s->name);
}

In the main program, I initialize 2 streams with different names. I call run start_reading(), sleep(3) and stop_reading()). The program prints the stream names fine for 3 seconds, but the pthread_join does not return successfully. It returns 3 and prints out

pthread join error: Operation timed out
pthread_join returned with errer:: No such process

I think this may be a pointer issue? I may just be confused with order of operations with these pointers in the join pthread_join(*sm->streams[i], NULL); . I’ll look into that more.

  • 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-06T19:54:36+00:00Added an answer on June 6, 2026 at 7:54 pm

    pthread_create() takes a pthread_t* as its argument, this is passing a pthread_t**:

    pthread_create( (pthread*) &sm->threads[i],
    

    as sm->threads is an array of pthread_t*. Change stream_manager to:

    typedef struct {
      // ...other stuff
      pthread_t threads[MAX_STREAM_COUNT]; /* No longer array of pointers. */
    } stream_manager;
    

    and remove the unnecessary cast from the call to pthread_create().

    pthread_join() takes a pthread_t:

    pthread_join(sm->threads[i]); /* Not sm->streams[i]. */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a struct-array that contains details of different reports that can be run.
Hi there I have to read data from text file into the array in
I have the following struct: typedef struct _chess { int **array; int size; struct
I have a struct array called AnalysisResults , that may contain any MATLAB datatypes,
I have a struct with a dynamic array inside of it: struct mystruct {
I have a Deque that contains this kind of stucts. struct New_Array { array<array<int,4>,4>
I have this function in C++: struct MyObject { } testAlgorithm(array<String^>^ algorithms, MyObject^ myObject)
I have an array of structs and one of the fields in the struct
I have a byte array which needs to be marshalled into the following struct:
I have a struct with an array of 100 int (b) and a variable

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.