It was dictated to me taht my routine has to have a return value and it needs to be returned.
i.e :
int mySuperThread(void)
I start the thread and it does what it needs to do. The question being asked is how to continually restart the thread again and again and again to do its job while still being able to return an integer (which is generated thru the thread’s run…). Mind you, from my understanding, it is a requirement that i use the “return” call via the thread’s int return value.
Suggestions? I’m trying to figure out if there is some flag or functon that i’m missing that relates to pthreads that allows a thread to restart when it ends.
To start with, if you are calling the above function with pthreads, you’re probably having some trouble. The signature of the function pointer passed to
pthread_createmust bevoid * functionname(void*), which is to say, it must be a function that takes a single, pointer to void argument and return a pointer to void.Fortunately,
void*can be cast to and fromintwith relatively little pain, so your function’s return can look like:Getting that return value is a little more involved. You’re right in being confused about continuing the thread after the return; you can’t. What you want to do is join with the thread, which is just waiting until the thread returns. Once that’s done, you could restart the thread as you did before.