Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Can any body tell me what is advantage of static thread function ?

Can any body tell me what is advantage of static thread function ?

Scheduled Pinned Locked Moved Unsolved C++ Gurus
2 Posts 2 Posters 438 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by Qt embedded developer
    #1

    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);
    }
    
    jsulmJ 1 Reply Last reply
    0
    • Q Qt embedded developer

      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);
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved