I just started to get into threads in POSIX C, and I am confused how to create global array pthread_t t[NUM_OF_THREADS] where NUM_OF_THREADS should be determined at run time. I need to create a separate thread for each category my program receives, and it can be any number of categories.
So, I do not know how many threads I should create. Basically I am calculating the number of categories in my code, and I want to create the same number of threads in my program. How would I do that?
I cannot create a global array with some variable number for NUM_OF_THREADS, meaning that NUM_OF_THREADS should be constant. I also need this array of threads to be accessible from different functions. I am stuck.
How do you work with threads if you do not know their number before runtime?
Thank you