Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Question on Linux multithread programming

Question on Linux multithread programming

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
designlinuxquestion
1 Posts 1 Posters 2 Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cy163 hotmail com
    wrote on last edited by
    #1

    Hello, In my program, I first receive data from another machine, then processing the data. Data receiveing is fast, but data processing is relatively time consuming. Hence, I put the code for data processing in a POSIX thread (i am using RedHAt enterpriese linux 4). In the main() function, I receive data first. Whevenever a data is received, a new thread for data processing is created. I use the following code to test the above program design. It seemed dones not work.

    void * thread_func(void * arg)
    {

    printf("thread_func is running %s\n" ,(void *)arg);
    }
    main()
    {
    thread_t thread[100];
    char *str;
    int i;
    for(i=0; i<10; i++
    {
    str = (char*)malloc(sizeof(char)*200);
    strcpy(str, "Hello World\n");
    int ret;
    ret = pthread_create(&thread[i] ,NULLthread_func,(char *)str);
    printf("after pthread_cread ret= %d",ret);
    free(str);
    pthread_detach()thread[i];// I cannot use pthread_join here, since I could not wait until the current thread finishes there are a lot of incoming data arriving.
    }

    }

    I noticed the value of 'ret' is 0, indicating that 10 threads have been created successfully. However, I could not see the sentence "thread_func is running ...... Could anybody look at this code and let me know why it does not work . Thanks

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups