|
yes, i understood what your previous post said about this, and i know what is an active wait.
just paste here what MSDN say about sleep() (but give the entire text on it).
TOXCCT >>> GEII power
|
|
|
|
|
|
well, you didn't want to copy the text, i give you :
If you have a thread that uses Sleep with infinite delay, the system will deadlock.
How do you understand this ????
TOXCCT >>> GEII power
|
|
|
|
|
Well the context of this sentence deals with messages, and if you read a little bit more it reads
Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock
And this one makes sense. Think about a SendMessage call to all windows with no timeout and one of the threads sleeps endlessly. Then the calling process will also hang.
But I don't see this as an evidence that Sleep waits actively.
Jens
|
|
|
|
|
no messages are advised ! do you read entierely the particle or you only see some word ?!
MSDN says that if you have to create a nex thread, you mustn't use sleep() because of this problem.
TOXCCT >>> GEII power
|
|
|
|
|
The system will only deadlock if a message is sent to a window that is on a thread using "Sleep" in a non-alertable state. If you use "SleepEx", the second parameter allows the thread to wait in an "alertable" state.
A "SendMessage" queues an APC on the window's thread and will be processed if the thread is in an "alertable" state. So, if you use SleepEx() and maintain an alertable thread state you will be able to become signaled.
Sleep() is also a system call. It's not implemented in user-mode, so it doesn't do a while(x < 10). It's not a spinlock either. The thread should be delayed in the scheduler until the sleep has expired.
I'm not sure what the original question was, but it was something about going into a hibernate state. Perhaps this should answer the question (Link Below)
If this is true, I would think that the thread sleep would continue to sleep once the machine resumed, since it technically hasn't slept the full period. The only way it wouldn't is unless the scheduler bases the sleep off of time (Which would have changed) and it processes this information upon restart. Of course, even if it is based off of time, generally the OS is probably notified of a hibernation and it could make special arrangements to honor the full sleep independent of the hibernation, ie, resume after the system restarted.
I can't be sure of that without a test. You could write a thread to sleep and after the sleep write a debug message or something. Perform the test and verify the results. Though, generally speaking, the results could vary by implementation (hardware, OS, etc.) but most likely the implementations should match what you find.
http://www.veritest.com/benchmarks/battmark/bb3power_man/b3sleep.asp
Hibernation
Hibernation is one of several terms describing a state of reduced power consumption that a power-managed computer may support.
According to the conventional definition of hibernation, a notebook copies all memory contents and hardware state information to non-volatile storage (typically the hard disk, which requires no power to retain information), and the notebook is completely powered down.
Leaving hibernation and returning the system to full operation requires booting the computer as usual and then waiting while the system restores the memory contents and hardware state. The process is finished when the computer is at exactly the point it was when the hibernate process started.
Hibernation trades time for power: maintaining the system state requires no power (because the state has been saved to disk), so the computer can remain in hibernation indefinitely. However the user must wait when entering and returning from hibernation—sometimes several minutes or more if the system has a lot of memory.
|
|
|
|
|
BTW, Sleep() calls SleepEx with FALSE.
|
|
|
|
|
Well.. TEST IT !!
You can send a MessageBox after the Sleep() function, so if you start back up again and the message is on your screen it means that it worked.
I think is the best option...
|
|
|
|
|
I'm inclined to agree - just I got an attack of lazyitis and didn't want to hibernate a pc
|
|
|
|
|
I need source code for a program that copies itself into a certain directory with a certain name like "C:\Program Files\something.exe"
-Ryan M.
|
|
|
|
|
I'm not sure if an app that is running can be copied itself or even can be copied by other process...
|
|
|
|
|
It can - like this:
TCHAR szFileName[MAX_PATH];
::GetModuleFileName(szFileName, MAX_PATH];
LPCTSTR pszDest = _T("C:\\Program Files\\SomeApp.exe");
::CopyFile(szModuleFileName, pszDest);
|
|
|
|
|
look for [ShFileOperation] api!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi guys,
I've developed in C++ for many years, but more recently have been working in C# and VB.NET.
I am developing my own version of themed controls where the user can govern just about any aspect of control drawing, like shape and colour etc.
I want to extend this control now to Windows Captions (i.e. Form captions). One thing that I have never fully gained is an understanding of what windows messages to trap, whether to let the default processing always take place, and what values to return. Even when I think I am following the MSDN SDK documention on WM_... notifications I still can't seem to get it right.
My problem seems to mainly be in getting setup, i.e. calling GetWindowDC to give me the entire drawing area of the window. Once I have called GetWindowDC I can construct a .NET Graphics object, and later dispose of both after my drawing is complete.
I do this and clear the Graphics object to red, so I should see all the non-client area turn red, which happens when the window is first drawn, but after that, as I start to move the window or size it I dont see the DC get consistently filled with red.
In summary then, if I could get a control of non-client drawing then I would have raised my programming standard significantly.
I would really be immensley greatful if you guys could point me at a definitive guide to subclassing or window's message processing, without recommending 3rd part controls as I am a DIY fanatic! 8-)
Also, if any of you can spare some time now and again, perhaps on MSN messenger to chat about this issue that would just be solid gold.
I await your responses with baited breath!
Thanks all!
Nursey
|
|
|
|
|
Override the OnMessage method which recieves a Message structure.
|
|
|
|
|
Thanks but I know how to get to the messages. As I said the problem has always been what messages to process. To be specific, what messages do I have to trap and process if I want to take entire responsibility for NC processing/drawing? Do I always have to perform the default processing then do my thing?
See?
Thanks.
Nursey
|
|
|
|
|
All,
History:
I have a list control that I used the onclick event to perform action with.
The user wanted to be able to use the up/down arrows so I changed the event handler to use the itemchanged message.
Now:
The user wants to use both the mouse and the arrows - which is fine since the itemchanged message takes care of both of these actions. The problem being that the user also wants to be able to reperform (if that's a word)
the same actions (it's a function to do a lot of number crunching on some data) on the currently selected item. The problem is that the itemchanged message gets called 3 times and thus the number crunching takes place 3 times!
How do I get this to handle both mouse clicks and up/down arrows without having my function called 3 times?
Thanks in advance,
John
|
|
|
|
|
the function is called three times for the selected and the item that is being unselected(if thats a word )
so i am going by memory here
it is called once when the previously selected item is Unselected, then for the new item that is selected and the the newly selected item gains focus rect
examin the NM_LISTVIEW structure that is passed it contains the ItemNo and the Reason(selected, unselected etc) and then perform ur action
Hope it helps
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Like this (I think)
void CYourDialog::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) pNMHDR;
if(pnmv->uNewState & LVIS_SELECTED)
{
// do long running stuff
}
}
|
|
|
|
|
Thanks - that almost works...
It fails when I want to click on an already selected item and process data.
(I'm varying some algorithm params in the dialog and observing the effect).
So, I guess all I really want to do is to be able to use the up/down arrows to scroll and automatically process AND be able to use the mouse click to randomally select list data as well as process an already selected item.
Is this the correct approach (using these events or do I need to set and clear some global bool that I create to bypass all these cascading events?)
Thanks,
John
|
|
|
|
|
Yeah i don't think you get that event if you click on an already selected item... Have you tried processing NM_CLICK as well?
|
|
|
|
|
I have such block:
if (a > 0)
if (a > 255) b = 255;
else b = (BYTE)a;
else b = 0;
do anyone have an idea, how to make it works faster?
Thanx.
|
|
|
|
|
Not really faster, but certainly more obfuscated elegant:
b = a > 0 ? (a > 255 ? 255 : (byte)a) : 0;
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
thanx, but i need fast, not elegant
such construction works even slowly.
|
|
|
|
|
Try it and benchmark it. I can say nearly for certain that little block of code is nowhere near a slight resemblance of your bottleneck. (of course that is if a and b are bytes or ints as you lead me to believe) Rule number 1 of optimization: Don't do it. Rule number 2: Don't do it _yet_.*
So... Unless a profiler is telling you your code is bottle-necking at that small comparator block, I suggest you worry more about the rest of your code and just leave what you have. Things like passing function args by value rather than by reference, useless construction and destruction of temporary objects derived from complex class heiarchies, and other such subtle things are nearly 100% of the time your bottleneck. (Save for things like disk/network IO, etc.)
*Herb Sutter - More Exceptional C++
~Nitron.
ññòòïðïðB A start
|
|
|
|