Let’s say I have a text file composed like this
#####
typeofthread1
#####
typeofthread2
etc…
in my main I want to read that file, get the strings typeofthread1, typeofthread2 and create different threads using
pthread_t threads[NUM_THREADS];
for (i=0;i<NUM_THREADS;i++)
pthread_create(&threads[i], NULL, -> HERE <- , void * arg);
how can I put the just read typeofthread1, typeofthread2 strings into -> HERE <- making the main create two threads that point to two different thread prototype?
I want to do this because I want to create a program that creates different types of threads, depending on what I want to do, and choosing that from text file (sort of a configuration file)
any suggestion?
Map the string names to function pointers.
To select the proper thread function, loop over items in
mappingsand grab the function when the name matches.In wherever you launch the thread, you can use this as: