|
I had the same pb in this loop which was implemented in a thread :
while(TRUE)
{
...something to do
}
I found the solution by adding a Sleep() inside the loop like this :
while(TRUE)
{
... your code
Sleep(1); // 0 has no effect
}
Now, is it a bug from Microsoft ?
Hope that can help you.
|
|
|
|
|
i don't really think that this is a bug.. i think it is made per design.. in an endless loop you have to install a wait - object (sleep(1)) so that the other threads have got any chance to handle their messages... (think this is a general window - programming rule.. never use endless loops without a sleep)
i had that problem in some multithreaded programs too.. after insert sleep(1) it worked perfectly..
if anybody else has another workaround you're welcome
bernhard
stolen sig#16:
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."
|
|
|
|
|
This is what the documentation says abt WaitForSingleObject:
"The WaitForSingleObject function checks the current state of the specified object. If the object's state is nonsignaled, the calling thread enters the wait state. It uses no processor time while waiting for the object state to become signaled or the time-out interval to elapse."
It states that no processor time is used for timing out.Meaning WaitForSingleObject should sleep for altleast 300 Ms in this case till the object gets singnalled which it seems it is not doing.
Please correct me if i am wrong.
|
|
|
|
|
I think there are two possibilites for high CPU utilization:
1) TRACE - it may scroll and repaint the Output window. It's easy to check, just remove the call and check the utilization.
2) while WaitForSingleObject doesn't tax the processor during wait, it may use some cycles when entering and exiting the wait state. However, 300ms is quite long time to amortize these costs.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi,
In actual code i use a home grown version TRACE that logs to a file and is pretty fast enough.I just added the TRACE to make my point.The CPU utilization is still high.
|
|
|
|
|
see i can create event objects from my programme using createevent api.. it can create an event,good thing is i can name this event also, out side user mode of winnt or winx.
and i can access this event object from any of my other process provided this event object is inheritable, and u know the name of the object. so far things are fine.
now lets come to my problem, i want to access such an event object from one of my processes, but i dont know the name of the object. so that i have to write some piece of code which could enumerate all the event objects created at kernel/system level. so that i can choose the name of the event object and proceed further. if u see any solutions pls forward that to me as soon as possible.
exwhiz
|
|
|
|
|
Did you want to use OpenEvent() to open your event object? If you created the event object using the form CreateEvent(...,...,...,NULL), you had created an event object without a name. You should replace the last NULL with a string to specify the name of the event object, then you can use OpenEvent() using the name. Hope it can help you.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Hi, thanx for your reply, but u know actually i want to enumerate event objects present in the system (named events). that is i want to know from one of my programmes how many event objects are present at a time and what are they?
with regards,
|
|
|
|
|
Hi everyone,
I'm new to programming in C++ and have the following problem: I would like to Drawing lines (and other objects, ie squares, circles, etc) with OpenGL(like the Paint program in windows)with a MFC application.
I've created a MFC application that is linked to OpenGL. How do I created functions like the ones we see in the "Paint" program found in windows accesories?
For example, if I click on the menu which as a "draw lines" function and after clicking on that, I would like to use the mouse to draw lines, (line starts when the mouse is clicked and dragged. Then the line stops when mouse is released).
I'm having great difficulty doing this and if anyone can help it would be greatly appreciated.
Thank you in advance!
Steve
|
|
|
|
|
Why do you want to use OpenGL for a 2D paint system ?
You should go to nehe.gamedev.org ( or .com, I can't remember ) for OpenGL tutorials that will probably help. You should also buy the Red and Blue books if you're remotely serious about it.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Have a look at
http://www.opengl.org/discussion_boards/cgi_directory/Ultimate.cgi?action=intro&BypassCookie=true
which is an excellent forum about OpenGL programming. Have also a look at
http://nehe.gamedev.net/
where you can find tons of very well explained tutorials
|
|
|
|
|
For me it looks like you just want to draw simple objects.. (2d - graphics..)
and for that you don't need opengl.. the good 'ole gdi would be enough for that..
there are some examples for drawing in gdi on this page.. another way would be to follow the scibble example of the msdn..
but if i did understand you wrong, sorry..
bernhard
stolen sig#15:
"The content of this post is not necessarily the opinion of my yadda yadda yadda."
|
|
|
|
|
Does a Directory Selector Dialog exist as a standard dialog in MFC? I know it isn't a common dialog (unless FilePicker is configurable), but if it exists already I don't want to reinvent the wheel. If it doesn't exist, I guess I get to make one myself! Woo!
Thanks.
Platform: Win2k
Lang : Visual C++ with MFC
----
Xian
|
|
|
|
|
From memory it's SHBrowseForFolder. Yes, that's right.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
You rock, thanks.
----
Xian
|
|
|
|
|
Hi,
I cannot debug my program anymore since a few days. I must have made a change somewhere (but where ) and now everytime I try to set a breakpoint (in any part of my project) the following message appears:
One or more breakpoints cannot be set and have been disabled. Execution will stop at the beginning of the program.
Can anyone help??
Thanks
|
|
|
|
|
try a Rebuild All. you need to convince the debugger that it is looking at the latest build of the source. also, make sure you're building in debug mode..
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Hmmm, should I help the arch enemy of BatMan?
Anyway have a look at the following two KnowledgeBase articles. Hopefully one of them will help you.
Q146447 and Q78853.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
"Don't belong. Never join. Think for yourself. Peace"
- Victor Stone
|
|
|
|
|
I think you had switch the compiler into Release mode, so no breakpoints can be set. You can switch back to Debug mode in the menu Build --> Set Active Configuration.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Thanks for the many replys, but the cause is probably elesewhere because it is still not working
I remember removing a few project options which where not compatible with the "Maximize speed"-optimization. Could that be the cause? I tried to come back to "default"-optimization, but this didn't change anything
|
|
|
|
|
Are you sure you are in the Debug mode and not the Release mode?
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Yes, unfortunately I'm in debug mode...
Why can't the error message be a little more explicit
|
|
|
|
|
I think you had changed the settings for the debug mode.
You can try this solution:
Project-->Settings-->select Win32 Debug in "Settings For"
-->select "C/C++" tab-->select "General" in Category
-->select "Program Database for edit and continue" in "Debug Info"
then it should work normally.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
...and everything is working for the best now!
Thanks Chaos Lawful, you saved me for the second time
|
|
|
|
|
Codes described below read lines of a file and write those on another file:
CODE A:
CStdioFile ent;
CStdioFile sal;
CString stReg;
ent.Open("input.txt", CFile::modeRead);
sal.Open("output.txt", CFile::modeCreate | CFile::modeReadWrite);
while (ent.ReadString(stReg)) {
sal.WriteString(stReg);
sal.WriteString("\n");
}
runs extremely faster than:
CODE B
ifstream inp("input.txt");
ofstream outp("output.txt");
string sReg;
while(getline(inp, sReg))
salida << sReg << endl;
Is there anyway to make CODE B faster that CODE A
Thanks in advance!!!
|
|
|
|