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