473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Sleep thread from Main thread

Hi,

I am having an application which inserts some data into a table. While
inserting table rows, I want to check CPU percentage and if it is >90%
then I want to sleep insertion for some time and then again resume
it.

For example:

-Main execution starts
-Main starts inserting rows into table
-Check CPU %
-while ( CPU % 90 )
-Sleep(10000)
-End inserting
-End Main

Now if I create one thead to insert table values and second thread to
check CPU % from the main thread, then can we sleep the insertion
thread from the main thead? Main thead waits till the insertion
completes.

Please let me know your thoughts or any other way to resolve this
issue.

Regards,
PI
Dec 26 '07 #1
4 1990
<ip*****@gmail.comwrote in message
news:f8**********************************@s19g2000 prg.googlegroups.com...
[...]
Please let me know your thoughts or any other way to resolve this
issue.
If your purpose is to avoid hogging the CPU with your insertion process,
there is another alternative: You could create a thread to perform the
insertion and set the Thread Priority to "BelowNormal". In this way, when
other processes require the CPU, your thread will automatically "give way"
to them, and then immediately resume when the CPU is no longer busy at other
tasks.

Dec 26 '07 #2
Hi,

Alberto, gave a better alternative solution, you also can use the same
code with Monitor involved, by using Monitor.Wait.... and
Monitor.Pulse.... you can control the thread execution.

Regards,

On Dec 26, 3:48 pm, "Alberto Poblacion" <earthling-
quitaestoparacontes...@poblacion.orgwrote:
<ipra...@gmail.comwrote in message

news:f8**********************************@s19g2000 prg.googlegroups.com...
[...]
Please let me know your thoughts or any other way to resolve this
issue.

If your purpose is to avoid hogging the CPU with your insertion process,
there is another alternative: You could create a thread to perform the
insertion and set the Thread Priority to "BelowNormal". In this way, when
other processes require the CPU, your thread will automatically "give way"
to them, and then immediately resume when the CPU is no longer busy at other
tasks.
Dec 26 '07 #3
Hi,

Do not try to do the job of Windows, if the OS schedule 90% of CPU for a
particular project it might be the case that no other process is using it in
the first place.

Not only that after you "restart" your thread it will be reach 90% again.
so at the end what you are achieving is that instead of a short burst of 90%
utilization you are having several chunks of high utilization.


--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
<ip*****@gmail.comwrote in message
news:f8**********************************@s19g2000 prg.googlegroups.com...
Hi,

I am having an application which inserts some data into a table. While
inserting table rows, I want to check CPU percentage and if it is >90%
then I want to sleep insertion for some time and then again resume
it.

For example:

-Main execution starts
-Main starts inserting rows into table
-Check CPU %
-while ( CPU % 90 )
-Sleep(10000)
-End inserting
-End Main

Now if I create one thead to insert table values and second thread to
check CPU % from the main thread, then can we sleep the insertion
thread from the main thead? Main thead waits till the insertion
completes.

Please let me know your thoughts or any other way to resolve this
issue.

Regards,
PI

Dec 26 '07 #4
Hi,
I think that this si a better solution. Still I do not think that the
original situation is a problem in the first place.

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:uS*************@TK2MSFTNGP03.phx.gbl...
<ip*****@gmail.comwrote in message
news:f8**********************************@s19g2000 prg.googlegroups.com...
>[...]
Please let me know your thoughts or any other way to resolve this
issue.

If your purpose is to avoid hogging the CPU with your insertion
process, there is another alternative: You could create a thread to
perform the insertion and set the Thread Priority to "BelowNormal". In
this way, when other processes require the CPU, your thread will
automatically "give way" to them, and then immediately resume when the CPU
is no longer busy at other tasks.

Dec 26 '07 #5

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

Similar topics

0
by: Eric Marvets | last post by:
I want to make the main thread in my app sleep while I have a worker do some arbitrary task. The problem is waking the main thread back up. Can anyone make this code sample work? private void...
29
by: Jeffrey Maitland | last post by:
Hello all, I am in the process of writing a multithreading program and what I was wondering is a sleep command in an executing function will affect the threads below it? Here is a basic example...
5
by: Parahat Melayev | last post by:
I am trying to writa a multi-client & multi-threaded TCP server. There is a thread pool. Each thread in the pool will handle requests of multiple clients. But here I have a problem. I find a...
2
by: [Yosi] | last post by:
I have C# application, in main form I made thead... User click on susspend button which cause to suspend the thread, in the button fuction: mThread.Susspend(); What I should do to wait in this...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
7
by: davidst95 | last post by:
Hello, I have a program that runs a long process. I tried to add a thread to check if the use hit a cancel button to abort the process. Dim t As Threading.Thread t = New...
11
by: mark | last post by:
Right now I have a thread that sleeps for sometime and check if an event has happened and go back to sleep. Now instead I want the thread to sleep until the event has occured process the event and...
13
by: Charles Zhang | last post by:
Sleep() function Sleep at lease 1 millisecond, there is a way to make a thread to sleep less than a millisecond? One way I know of is using performance counter which is not really sleep ( loop and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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...
0
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...

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.