473,799 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pthread sleep cycle problem

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_in it(&tThreadAttr );

pthread_attr_se tdetachstate(&t ThreadAttr, PTHREAD_CREATE_ DETACHED);

pthread_attr_se tstacksize(&tTh readAttr, iSetStackSize);
//picGetInputpath is the directory path name where it
//has to look for the files
if ((dirBuff = opendir(picGetI nputpath)) != NULL){
while ((direntBuff = readdir(dirBuff )) != NULL){
//picExtension is the entension of the file name to which
//am comparing with.
if (!(iCOMPARE(dir entBuff->d_name, picExtension))) {
picFullPath = new char[strlen(picGetIn putpath) +
strlen(direntBu ff->d_name)+ strlen(picRenam eExtension) + 2];
strcpy (picFullPath, picGetInputpath );
strcat (picFullPath, "/");
strcat (picFullPath, direntBuff->d_name);
pthread_create (&tThreadId, &tThreadAttr , PCLoadINDOUT,
(void*)picFullP ath);
}
sleep(5); // main problem -- making all the threads already created to
sleep.
}
}

pthread_attr_de stroy(&tThreadA ttr);

Let me know if you need any more information.
Thanks,
lokb

Jul 22 '05 #1
7 4376
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
Jul 22 '05 #2
I am building this application on AIX 5L, using c++.

Tha C++ library used is pthread.h

Jul 22 '05 #3

"lokb" <lo***********@ rediffmail.com> wrote in message
news:1b******** *************** *******@localho st.talkaboutpro gramming.com...
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

Jul 22 '05 #4
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.programmin g.threads or in a newsgroup dedicated to your operating
system.

--
Peter van Merkerk
peter.van.merke rk(at)dse.nl
Jul 22 '05 #5
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

Jul 22 '05 #6
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

Jul 22 '05 #7
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.programmin g.threads
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
5706
by: Ryan Spencer | last post by:
Hello Everyone, I want to have a row of periods, separated by small, say, .5 second intervals between each other. Thus, for example, making it have the appearance of a progress "bar". import time sleep(.5)
26
2387
by: news.microsoft.com | last post by:
Hi, Currently I have a thread thats spinning and doing a Thread.Sleep(someTime). I was thinking of changing this to Thread.Sleep(Timeout.Infinite); then when I have actual data in a collection to process in this thread, I was going to do a _thread.Interrupt(); Would this be a better approach to spinning a thread on ?
9
8000
by: nan.li.g | last post by:
Hello, all, I have an interesting problem about stl map and pthread on Linux and g++. The source code is as follows. //mt_map_test.cpp #include <string> #include <map> #include <unistd.h> #include <sys/types.h>
10
4971
by: david wolf | last post by:
The following pthread code cannot compile, I want to know why. Can somebody give me direction on this? if I replace the following line of code status1 = pthread_create(&threadID1, NULL, read, NULL); with: status1 = pthread_create(&threadID1, NULL, readerWriter::read, NULL);
3
12331
by: Douwe | last post by:
I'm trying to write a piece of C code that has two threads: The first thread waits for a socket connection. The second thread is in a continues cycle waiting for an period of time (lets say 500 ms) or an incomming socket connection (received from the first thread). At this moment I've created two threads were the first one is already waiting for an incomming socket connection. I've also created a timer with timer_create. My problem is that...
2
3614
by: fran | last post by:
Server: IBM XSERIES 225 (Intel Xeon CPU 2.40GHz 1GB RAM) Operating System: Linux RedHat ES 2.1 kernel 2.4.9 Languaje: C++ Compiler: gcc 2.96 Libs: pthread We are in need of your help in order to solve the folowing problem: We´re working on a server side application that implements threads (pthread under linux Red Hat ES 2.1 kernel 2.4.9). The problem seems
10
5518
by: noleander | last post by:
I've got an application that uses Pthread to do threading. Mostly Im using Condition Variables and the associated function calls: - pthread_cond_wait() - pthread_cond_signal() - pthread_cond_broadcast() My boss says we cant use Pthread because of licensing issues (LGPL) .. we can only use Native Win32 threading/mutex functions.
21
2138
by: JackCoke | last post by:
Hello. I am new at this so forgive me if there is a simple answer, although it is one I could not find. My VB 2003 program can scan a folder, determine the size of the file it finds, wait 30 seconds, then determine the size of the file at that point. I wait the 30 seconds by using the Thread.Sleep method. Is there a way to wake the sleep cycle early by having the user click a button? -- Thanks for your help.
4
2838
by: KDr2 | last post by:
i just want to put *pthred_create* , *pthread_join* into one class, but i do not know how to, anyone help me? the code below is mine: ------------------------------ #include <pthread.h> #include <iostream> using namespace std;
0
9689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.