Pthread sleep cycle problem

Discussion in 'C++' started by lokb, Jul 14, 2004.

  1. lokb

    lokb Guest

    Hi,
    I am creating a detach thread as shown below and caling pthread_create in
    a while loop where the file names in the directory are fetched and is
    passed as a parmater to pthread create. The apilcation is running fine
    except for the sleep cycle.
    My sleep cylce is sleep(5) which is halting all the threads created from
    execution. What i need here is the main thread creating the pthread should
    only sleep but not all the threads created.
    Is there any best way other than sleep to do that.
    Plz suggest.
    I am including the snapshot of the code to be more precise in what we
    are doing.

    code snapshot
    =============
    pthread_attr_t tThreadAttr;
    pthread_t tThreadId;
    pthread_attr_init(&tThreadAttr);

    pthread_attr_setdetachstate(&tThreadAttr, PTHREAD_CREATE_DETACHED);

    pthread_attr_setstacksize(&tThreadAttr, iSetStackSize);
    //picGetInputpath is the directory path name where it
    //has to look for the files
    if ((dirBuff = opendir(picGetInputpath)) != NULL){
    while ((direntBuff = readdir(dirBuff)) != NULL){
    //picExtension is the entension of the file name to which
    //am comparing with.
    if (!(iCOMPARE(direntBuff->d_name, picExtension))){
    picFullPath = new char[strlen(picGetInputpath) +
    strlen(direntBuff->d_name)+ strlen(picRenameExtension) + 2];
    strcpy (picFullPath, picGetInputpath);
    strcat (picFullPath, "/");
    strcat (picFullPath, direntBuff->d_name);
    pthread_create (&tThreadId, &tThreadAttr, PCLoadINDOUT,
    (void*)picFullPath);
    }
    sleep(5); // main problem -- making all the threads already created to
    sleep.
    }
    }

    pthread_attr_destroy(&tThreadAttr);

    Let me know if you need any more information.
    Thanks,
    lokb
    lokb, Jul 14, 2004
    #1
    1. Advertising

  2. lokb wrote:
    > I am creating a detach thread as shown below and caling pthread_create in
    > a while loop where the file names in the directory are fetched and is
    > passed as a parmater to pthread create. The apilcation is running fine
    > except for the sleep cycle.
    > My sleep cylce is sleep(5) which is halting all the threads created from
    > execution. What i need here is the main thread creating the pthread should
    > only sleep but not all the threads created.
    > Is there any best way other than sleep to do that.
    > Plz suggest.


    Nether mentioned function is part of C++ standard library. As such
    their behaviour is unknown here. Post your platform-specific question
    to a platform-specific newsgroup, please.

    V
    Victor Bazarov, Jul 14, 2004
    #2
    1. Advertising

  3. lokb

    lokb Guest

    I am building this application on AIX 5L, using c++.

    Tha C++ library used is pthread.h
    lokb, Jul 14, 2004
    #3
  4. lokb

    Howard Guest

    "lokb" <> wrote in message
    news:...
    > I am building this application on AIX 5L, using c++.
    >
    > Tha C++ library used is pthread.h
    >


    Understood. But that doesn't make it topical to this newsgroup. This is a
    language newsgroup, where the discussions are intended to revolve the C++
    language, as defined by the C++ Standard. It's not a group for discussing
    issues with implementing C++ code on specific platforms, or for
    platform-specific tasks such as threads, graphics, file systems, etc.

    You'll get much better responses in a newsgroup devoted to the platform
    (operating system) or toolset you're programming for.

    -Howard
    Howard, Jul 14, 2004
    #4
  5. lokb wrote:
    > Hi,
    > I am creating a detach thread as shown below and caling pthread_create in
    > a while loop where the file names in the directory are fetched and is
    > passed as a parmater to pthread create. The apilcation is running fine
    > except for the sleep cycle.
    > My sleep cylce is sleep(5) which is halting all the threads created from
    > execution. What i need here is the main thread creating the pthread should
    > only sleep but not all the threads created.
    > Is there any best way other than sleep to do that.


    pthread functions are not part of the standard C++ library, so your
    question is not topical here. Your question would be more topical in
    comp.programming.threads or in a newsgroup dedicated to your operating
    system.

    --
    Peter van Merkerk
    peter.van.merkerk(at)dse.nl
    Peter van Merkerk, Jul 14, 2004
    #5
  6. lokb

    lokb Guest

    Hey
    sorry for the posting, I am searching for a forum to post this question
    and i posted in same question in couple of forums but didn't get a
    response.
    Can u plz let me know whats the newsgroup under talkabout programming
    this question would fit.
    Thanks in advance for directing me.
    Thanks,
    lokesh
    lokb, Jul 14, 2004
    #6
  7. lokb

    lokb Guest

    Hey
    sorry for the posting, I am searching for a forum to post this question
    and i posted in same question in couple of forums but didn't get a
    response.
    Can u plz let me know whats the newsgroup under talkabout programming
    this question would fit.
    Thanks in advance for directing me.
    Thanks,
    lokesh
    lokb, Jul 14, 2004
    #7
  8. lokb

    red floyd Guest

    lokb wrote:
    > Hey
    > sorry for the posting, I am searching for a forum to post this question
    > and i posted in same question in couple of forums but didn't get a
    > response.
    > Can u plz let me know whats the newsgroup under talkabout programming
    > this question would fit.
    > Thanks in advance for directing me.
    > Thanks,
    > lokesh
    >

    comp.programming.threads
    red floyd, Jul 14, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. R Mar
    Replies:
    0
    Views:
    400
    R Mar
    Jan 3, 2004
  2. Gonzalo Moreno
    Replies:
    2
    Views:
    12,417
  3. Replies:
    9
    Views:
    589
  4. Sam Roberts
    Replies:
    16
    Views:
    376
    Daniel Berger
    Feb 18, 2005
  5. Richard
    Replies:
    7
    Views:
    226
    Richard
    May 22, 2007
Loading...

Share This Page