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.