Pthread sleep cycle problem

L

lokb

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
 
V

Victor Bazarov

lokb said:
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
 
L

lokb

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

Tha C++ library used is pthread.h
 
H

Howard

lokb said:
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
 
P

Peter van Merkerk

lokb said:
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.
 
L

lokb

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
 
L

lokb

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
 
R

red floyd

lokb said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top