473,769 Members | 7,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How long should last a thread???

Hello,

I need a buffer reinitialized approx. once in each second (I think
this is quite often). Now I think to do the reinit within a separate
thread (I am using boost::thread). Well, filling the buffer is a real
short task but must be done very often (at least once in a second).

So what is the guide line how often a thread should be created and how
long it should last???

Thanks for your help
Chris
Dec 1 '07 #1
4 1677
On Dec 1, 12:01 pm, christian.si... @gmail.com wrote:
Hello,

I need a buffer reinitialized approx. once in each second (I think
this is quite often). Now I think to do the reinit within a separate
thread (I am using boost::thread). Well, filling the buffer is a real
short task but must be done very often (at least once in a second).

So what is the guide line how often a thread should be created and how
long it should last???
Have you read about thread pools? An application that uses
such a pool will reuse threads over it's lifetime.

Your post though, could be improved with more detail/context
and I would consider posting it on comp.programmin g.threads
or Boost Users newsgroup.

Brian Wood
Ebenezer Enterprises
www.webebenezer.net

Dec 1 '07 #2

<ch************ *@gmail.comwrot e in message
news:08******** *************** ***********@e23 g2000prf.google groups.com...
Hello,

I need a buffer reinitialized approx. once in each second (I think
this is quite often). Now I think to do the reinit within a separate
thread (I am using boost::thread). Well, filling the buffer is a real
short task but must be done very often (at least once in a second).

So what is the guide line how often a thread should be created and how
long it should last???
This is really off-topic here, as the question has nothing to do with C++.

However, the short answer to your question is, it all depends on the
application.

Generally speaking, create a thread only if it is necessary. Thread
creation can be an expensive operation in terms of time, so creating a
thread every second *could* affect your application's performance, depending
on what it is doing. It sounds to me like the easiest thing to do would be
to create just one thread when the program starts up, and let that thread
run in an infinite loop in which it does the re-init and then goes to sleep
for one second on each iteration. That would allow it to re-initialize your
buffer every second as you want, without the need for creating/destroying a
new thread every time.

- Dennis
Dec 1 '07 #3
On Dec 1, 7:57 pm, "Dennis Jones" <nos...@nospam. comwrote:
<christian.si.. .@gmail.comwrot e in message
news:08******** *************** ***********@e23 g2000prf.google groups.com...
I need a buffer reinitialized approx. once in each second (I think
this is quite often). Now I think to do the reinit within a separate
thread (I am using boost::thread). Well, filling the buffer is a real
short task but must be done very often (at least once in a second).
So what is the guide line how often a thread should be created and how
long it should last???
This is really off-topic here, as the question has nothing to do with C++.
However, the short answer to your question is, it all depends on the
application.
Generally speaking, create a thread only if it is necessary. Thread
creation can be an expensive operation in terms of time, so creating a
thread every second *could* affect your application's performance, depending
on what it is doing. It sounds to me like the easiest thing to do would be
to create just one thread when the program starts up, and let that thread
run in an infinite loop in which it does the re-init and then goes to sleep
for one second on each iteration. That would allow it to re-initialize your
buffer every second as you want, without the need for creating/destroying a
new thread every time.
Alternatively, why use another thread at all. Another thread
means that all accesses will have to be locked, etc. Depending
on the exact application, it might be simpler to just position a
time stamp each time he initializes the buffer, and check the
time stamp and do the reinitializatio n each time he uses it.

Of course, if the "reinitializati on" is really an update of real
time data, which the main thread is reading, and the update
takes a significant amount of time, then there can be problems
of latency. In that case, he probably needs a pair of buffers,
the reading thread uses one, the writing thread the other, and
the writing thread swaps them when it finishes an update. (One
of the applications I'm currently working on does this, except
that the reader isn't a different thread, it's a different
process, and the buffers are in shared memory.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 2 '07 #4
On Dec 1, 8:01 pm, christian.si... @gmail.com wrote:
Hello,

I need a buffer reinitialized approx. once in each second (I think
this is quite often). Now I think to do the reinit within a separate
thread (I am using boost::thread). Well, filling the buffer is a real
short task but must be done very often (at least once in a second).

So what is the guide line how often a thread should be created and how
long it should last???

Thanks for your help
Chris
You can use single thread which waits for a semaphore
( thread safe counting value wrapped so your thread will sleep until
another thread changes the value)
When you need reinitializing a buffer, you can post the semaphore to
allow waiting thread to reinitialize
the buffer ( protected by some mutex)
Dec 3 '07 #5

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

Similar topics

40
1743
by: Anony | last post by:
Hi All, I'm trying to chunk a long string SourceString into lines of LineLength using this code: Dim sReturn As String = "" Dim iPos As Integer = 0 Do Until iPos >= SourceString.Length - LineLength sReturn += SourceString.Substring(iPos, LineLength) + vbCrLf iPos += LineLength
11
5312
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our 4-month old C#/MC++ .NET project project. I'd like to thank in advance anyone who takes the time to read and/or respond to this message. At a couple points, it may seem like a rant against C# / .NET, but we are pretty firmly stuck with this approach...
18
5860
by: Urs Vogel | last post by:
Hi I wrote an application server (a remoting sinlgeton), where processes must be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and only after a Thread.Abort(), this component becomes instabile, throwing a Windows like error (access violation on 0x00000002), not an framework exception. The component and all of its subcomponents are 100% managed code. What could go wrong with Thread.Abort()? Thanks for any hints.
9
7135
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but when I tried the program on the Win98 system it will be running on, I get the following error: Cast from string "2076719" to type 'Long' is not valid I am not sure why I only get this error on the Win98 system or how to go about correcting...
18
2210
by: Larry Herbinaux | last post by:
I'm having issues with garbage collection with my long-standing service process. If you could review and point me in the right direction it would be of great help. If there are any helpful documents that you could point me to help me control the GC, then that would be great also. The .Net GC does not cleanup memory of our service process unless it is forced to by another process that hogs memory. · GC Algorithm - This is an issue...
11
1931
by: Ryan Liu | last post by:
In Visual Studio 2003, when i debug a C# program, I found: 300L * 10000000l -1294967296 int 210L * 10000000L 2100000000 int How come? a long type can not handle 300L * 10000000l, the result is too big for long type? Thanks!
3
4352
by: lai_waiman | last post by:
Dear All, I have problems on doing some long lasting job in a web services. Let me first provide some background information first. I have a ASP.NET web page, which will call another Web Services to preform a task. Since that Web Service Task last for a quiet long time (eg. 1 hr). If I return the result after the long task, I am sure that the client browser will be timeout. So I decided to use threading inside the Web Service. My...
73
7454
by: Yevgen Muntyan | last post by:
Hey, I was reading C99 Rationale, and it has the following two QUIET CHANGE paragraphs: 6.5.3.4: "With the introduction of the long long and extended integer types, the sizeof operator may yield a value that exceeds the range of an unsigned long." 6.5.6: "With the introduction of the long long and extended integer
8
2564
by: jr | last post by:
I have an application the makes a call to a webservice to retrieve some additional info for my app. The information I get back is non-essential, so I do NOT want my entire app hanging to wait for this repsonse if it takes more than, say, 2 seconds to a response from the webserver. Basically, how would I immediately end a function that is taking too long to respond? --
0
9589
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
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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

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.