I program using pthreads in C.
I have a parent thread that needs to create 4 child threads with identifiers 0, 1, 2, 3. When the parent thread receives the data, it will separate the data and assign it 4 separate context variables - one for each sub-thread. Subtopics must process this data, and at the same time, the parent thread must wait for these threads. After these subtopics have completed, they will set the output in the appropriate context variables and wait (for reuse). Once the parent thread knows that all of these subtopics have completed this round, it computes the global output and prints it. Now he is waiting for new data (subtopics are not yet killed, they are just waiting).
If the parent thread receives more data, the above process repeats itself - albeit with 4 threads already created.
If the parent thread receives the kill command (assuming a specific data type), it points to all subtopics and terminates them. Now the parent thread may terminate.
I am a graduate student and I am faced with the need for the above scenario. I know this can be done using pthread_cond_wait, pthread_Cond_signal. I wrote the code, but it works unlimitedly, and I cannot understand why.
I assume that as I encoded it, I too complicated the script. It will be very useful to know how this can be implemented. If necessary, I can publish a simplified version of my code to show what I'm trying to do (although I believe that my approach is corrupted!) ...
- , pthreads?