Can any body tell me what is advantage of static thread function ?
Unsolved
C++ Gurus
-
I want to know what is advantage of static thread function ?
static void * threadFunc(void *arg) { char *s = (char *) arg; printf("%s", s); return (void *) strlen(s); } int main(int argc, char *argv[]) { pthread_t t1; void *res; int s; s = pthread_create(&t1, NULL, threadFunc, "Hello world\n"); if (s != 0) errExitEN(s, "pthread_create"); printf("Message from main()\n"); s = pthread_join(t1, &res); if (s != 0) errExitEN(s, "pthread_join"); printf("Thread returned %ld\n", (long) res); exit(EXIT_SUCCESS); }
-
@Qt-embedded-developer In this case static simply means the threadFunc is only accessible from this translation unit (see https://www.sandordargo.com/blog/2021/07/07/2-ways-to-use-static-with-functions-cpp). It has no real "advantages" here.